Perl Regular expression to java Regular Expression

HI all,
How can i write java Regular expression for the below Perl Code
where data.html is my original Html file
and data2.html is output file.
open(FPR, "data.html") || die("Could not open data file");
while ($line=<FPR>) {
$content .= $line;
close(FPR);
open(FPR, ">data2.html") || die("Could not open data2 file");
# clean white spaces
$content =~ s/[\n\r\0 ]//g;
# divide data by td
$rxp='<tr.*?><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><\/.*?tr>';
while ($content=~ m/$rxp/g)
print FPR "\n".$1."\t".$2."\t".$3."\t".$4."\t".$5."\t".$6."\t".$7."\t".$8."\t";
print FPR "<br>";
close(FPR);
can you help in this regard
Thanks

I am able to retrive only one row in this format from data.html file
<trvalign=middlebordercolor=#ffffff><tdwidth='40'CLASS='tdbgpricespagecolorgrey'><fontface='Arial,Helvetica,sans-serif'size='2'>SB</font></td><t
dwidth="23"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sansserif'size='2'>USAirways</font></td><tdwidth="34"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>MIA</font></td><tdwidth="31"Class=tdbgpri
cespagecolorgrey><fontface='Arial,Helvetica,sans-erif'size='2'>LGW</font></td><tdwidth="23"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>USAirways</font></td><tdwidth="34"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>LGW</font></td>
But i need the output in this format
<fontface='Arial,Helvetica,sans-serif'size='2'>SB     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA     <fontface='Arial,Helvetica,sans-serif'size='2'>LGW     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>LGW     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA          <br>
<fontface='Arial,Helvetica,sans-serif'size='2'>CS     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA     <fontface='Arial,Helvetica,sans-serif'size='2'>LON     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>LON     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA          <br>
How can i rewrite the code to achive this.
Here is my java code
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class parseHTML {
public static void main(String[] args)
try
BufferedReader in = new BufferedReader(new FileReader("C:\\data.html"));
PrintWriter out = new PrintWriter(new FileWriter("C:\\data1.html"));
String aLine = null;
String abc=null;
String pattern1 ="<tr.+?><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td>++";
Pattern p1 = Pattern.compile(pattern1);
while((aLine = in.readLine()) != null)
abc=aLine.replaceAll("(\n|\t|\r)","").replaceAll(" ","");
Matcher m1 = p1.matcher(abc);
if(m1.find())
System.out.println("the value is...."+m1.group());
out.print(m1.group());
m1.reset(aLine);
in.close();
out.close();
catch(IOException exception)
exception.printStackTrace();
Thanks

Similar Messages

  • Where in the chomsky hierachy are java/perl regular expressions?

    hi,
    does anyone know (or of any links that talk about) where java/perl (they are the same?) regular expressions fit in the chomsky hierachy (and which operators take them out of the regular languages?)?
    thanks,
    asjf

    does anyone know (or of any links that talk about)
    where java/perl (they are the same?) regular
    expressions fit in the chomsky hierachy (and which
    operators take them out of the regular languages?)?From a mathmatical viewpoint, regular languages can always be described by regular expressions. I've always assumed java/perl were the same. I looked at the all the possible patterns listed(http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum) and I know I easily could create a finite state machine for any of expressions listed except in the last section. This would prove they are regular languages. The reason I can't do the last section is because I don't understand what they mean. I don't know understand what they mean by things like 'X, via zero-width positive lookahead' and a quick google search didn't give me any good examples/clarifications.

  • Executing a perl script from within java application

    Hi,
    Does anyone knows a way to execute a perl script from within java.
    ---kirk

    Runtime.exec("perl myscript.pl");
    Of course whether that "works" depends on what the script does and where the java program runs.

  • Perl script calling a java program

    Hello,
    I have the following perl script that executes a java program called TestSe. It passes its QUERY_STRING to the java program after printing it.
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    $in = $ENV{'QUERY_STRING'};
    print $in;
    exec 'java TestSe '.$in;
    This script in placed in a cgi-bin directory on a server.
    This script works when i run it manually and hardcode a string value in $in by doing
    $in="Acheck";
    It prints 'Acheck' on the screen and invokes the java program with Acheck as the parameter.
    I tested it by typing
    'perl try.cgi' on the shell after logging into the server.
    However when I execute this script via. a browser then it does not exec the java program.
    The QUERY_STRING is the papameter passed to this script by an html form in a browser that invokes it. The script can print the value of $in in the new browser window that it creates but it is not execing the java program.
    Does anyone kow why?
    Thanks

    Perhaps java isn't in the PATH for the server

  • Run Perl script in my Java program

    Some say that the following statement can run Perl script in Java program:
    Runtime.getRuntime().exec("C:\\runPerl.pl");
    But when I run it, it'll throw IOException:
    java.io.IOException: CreateProcess: C:\runPerl.pl error=193
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:63)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at test.runPerl.main(runPerl.java:16)
    Exception in thread "main"
    Where is the problem? In fact, I do have a Perl script named "runPerl.pl" in my C:/ directory. Why can't it be run?

    Please don't crosspost
    http://forum.java.sun.com/thread.jspa?threadID=703918

  • Calling a perl programme from client java programme

    Hello
    I have an application with client code in java. On server side resides perl script to which my client java is dealing with.
    The server is linux debian distro while client is window.
    In actual processing I am uploading file(with specific format) from my java client application to server.
    After all the processing at server sideI am getting CVS file on my client machine. Now all this process is working smoothly except in following case.....
    The above application is developed for japanese clients. So in this application the folder names containing the files on client machine are in japanese. Now there are some cases when the folder names contain the metacharacters for linux. In this case when I submit the whole path of file, I want to upload then due to this metacharacters I think the command for submitting the file to perl is not able to execute properly on the linux server machine. So in that case my application hangs.................
    I am really looking for any solution for above problem...................
    Thanks in advance...........
    Pasi

    Convert what?Definitey I want to convert file/path
    name............................
    If the file/path name then replace every character
    (not byte) that has a value outside of the range of
    valid characters. You can just abritrary choose a
    range like [A-Za-z0-9_]. Replace each character
    either with a underscore or an 'escaped' value like a
    char whose hex value is c900 would produce a new value
    of "_Zxc900"As you have written above I have to just find the
    characters outside
    the valid range. But here the problem is when
    I submit the file/path from java client programme to linux server
    I am submitting it in japanese so at that time I am not able to
    understand how to check the characters outside valid
    range.
    Is the client in java. All strings in java are in unicode. So if you use toCharArray() you get a UTF16 representation. Any character above 128 is suspect. And some characters below 128 are suspect. The range I gave above is below 128 and can be used to filter for the others.
    So while submitting the file/path to server do I have to first convert
    it into server compatible charset. Then to check for
    unvalid characters....
    Is it the right procedure..................
    Would you please elaborate on this issue...........
    Hope this co-operation from you.Pseudo code
    - Use toCharArray()
    - For each char in the array.
    ---- Is it in the range? Then leave it.
    ---- Is it outside the range? Then convert it.

  • Executing perl/c modules from java appln

    Hi,
    I need to integrate some modules written in Perl/C/C++ , which take a filename as input and stores the ouput in a file. I need to provide the interface in Java. Plz let me know how to execute perl or c++ file with input parameters.
    Thanks in advance

    Runtime.exec()

  • MMS-Perl 8130: uncaught exception:java.lang.nullpointerException

    Wondering if anyone can help me on this as it is driving me nuts and no one at Bell can provide any assistance. I have to keep doing a hard refresh to clean this out, but it always returns. Is there a reasons this comes up all the time? Could it be my hardware? Someone mentioned it could be a person that I added, but can't figure out which person it might be. Could it be that I don't have a pin set up for a specific person. I apologize for my ignorance, but I can't figure this out and nobody I talk to seems to know.
    Any help would be much appreciated.
    Thanks
    Stefan

    If you have installed and 3rd party apps like googlemail etc, go to options-advanced options-application then scroll to the instaled app and change the permission to allow. save and exit. Restart App. and there is no problem worked for me hope it does for you too.. Pls. message me if it works
    cheers
    EDIT: Removed personal information
    Message Edited by Andy on 08-14-2008 08:58 AM

  • Please recommend a good tutorial for Regular expressions?

    I have several PERL programs that I need to translate in to JAVA for performance reasons. Those programs heavily use Regular Expressions. I have an excellent knowledge about PERL Regular Expressions but know very little about Java Regular Expressions.
    So Can any one of you recommend me a good tutorial for Java Regular Expressions.
    Thankx In Advance
         LRMK

    Since you know regexs, the java.util.regex.Pattern class API is probably all you need, it pretty thoroughly documents Java's flavor, and the differences from PERL's flavor.

  • IR filter using "matches regular expression"

    Hi,
    I am familiar with Perl regular expressions, but I'm having trouble using the IR filter by regular expression in Apex.
    For instance, I would like to search for dates of format 'MM/DD/YY' - can someone tell me how this would be done? I tried '[0-9](2)/[0-9](2)/[0-9](2)' and many other patterns to no avail.
    Also can you point me to a good thread for regular expressions in Apex?
    Thanks for any help.

    Hi,
    you can play around with oracle regular expressions at
    http://www.yocoya.com/apex/f?p=YOCOYA:REGEXP_HOME:0:
    It's an Apex application, albeit "seasoned", where you can build and test the regex and it will be 100% compatible as it runs natively, so it's not simulated on a different platform.
    Most likely the IR filter will make use of REGEXP_LIKE so you can pick that function from the menu.
    Flavio
    http://oraclequirks.blogspot.com
    http://www.yocoya.com

  • Difference between Java and Perl?

    I'm new to Java and was wondering what is the difference between Java and Perl. Other than Java has to be compiled and Perl does not. Is one better than the other? Here is a link to my website. The languaged used is Perl. Can Java be used to write a program like this.
    http://www.i2r2.co.nr

    Perl - interpreted
    Java - compiled (essentially -- there is no eval statement)
    Perl - lots functionality built into the bare language
    Java - more functionality moved into libraries
    (both have huge libraries available though -- and Java's core language seems to get bigger with each new release)
    Perl - loosely typed
    Java - strongly typed
    IMHO:
    Perl - Baroque ornate language good for quick scripts
    Java - Calvinist spartan language good for huge projects
    I can't think of anything else to say that can't be expressed in one-liners.

  • Calling Perl module in Java

    Hai,
    I like to know, How do I call a perl module from my java program such that the
    output of the perl module is used in my Java program ?
    Regards
    ackumar

    This is my sample perl program.
    #!/usr/bin/perl
            $s=hello();
            print "$s\n";
            sub hello{
                    return "HELLO WORLD"
            }I like to use the perl program in my java program. So I wrote the following code.
    But I don't know how to get the output "HELLO WORLD" of my sample.pl by running my code
    perl_java. java
    import java.lang.*;
    import java.io.*;
    class perl_java{
            public static void main(String args[]){
                    try{
                    Process p = Runtime.getRuntime().exec("perl sample.pl");
                    OutputStream os=p.getOutputStream();
                    }catch(Exception ee){ee.printStackTrace();}
    }

  • How to run the perl script from java ?

    Hi , I need to run the pearl script from the server and to get the result of the script thro' java using SSH
    Is there any 3rd party SSH API in java ?
    Please help me out
    thanks in advance
    karthik

    This seems like a very strange thing to want to do.
    What is the perl script doing?
    Do other programs (not some shell script) access this server-side perl script from a different machine?
    If so how do they do it?
    What currently triggers the perl script to execute?
    What currently handles the output from the perl script?
    If you can answer these questions (and understand the answers) you should be able to come up with a different approach to this.
    You do not really want to call a remote perl script from a Java program, you want to achieve the effect you think that would have if you could do it.
    So find the answers to the above questions, write them on 3" x 5" cards and lay them out on your desk.
    What flow of control needs to happen? Which piece of code needs to produce or consume which piece of data?
    If that fails, ask you self or who ever is making you do this what are the use-cases?
    If you do not know what use-cases are or do not understand them well enough try reading
    Use Case Modeling (The Addison-Wesley Object Technology Series) by Kurt Bittner and Ian Spence (Paperback - Aug 30, 2002)
    http://www.amazon.com/s/ref=nb_ss_gw/002-7908514-4043267?url=search-alias%3Dstripbooks&field-keywords=use+cases&x=0&y=0
    It is a short and easy to read book on the subject and also one of the best.
    You MUST understand WHAT you are trying to achieve before you can decide HOW you are going to achieve it.

  • Execute perl-script using java

    Hi All
    I would like to execute a perl script (inside a java app) and retrieve its output. This java program needs this output.
    Can someone give me information on how to do this ?
    Thanks a lot in advance
    Luca

    Ok, solved it:
    import java.lang.Runtime ;
    import java.io.* ;
    public class Test {
         public static void main ( String ARGV[] ) {
              Runtime r = Runtime.getRuntime() ;
              Process p = null ;
              DataInputStream dis = null ;
              String s ;
              try {
                   String cmd[] = new String[1] ;
                   cmd[0] = "./a.pl" ;
                   p = r.exec(cmd) ;
              dis = new DataInputStream(p.getInputStream());     // create file I/O
                   s = dis.readLine();     
                   System.out.println("|"+s+"|") ;
                   s = dis.readLine();     
                   System.out.println("|"+s+"|") ;
              catch(IOException e) {}
    }

  • How would java compare to Perl for processing large txt files

    I guess what I am asking is that I write a lot of scripts in perl for processing txt files with large amounts of data in them ( >1 MB or >100K Lines of data )
    Stuff like searching for strings, deleting chuncks of the file, replacing strings, extracting strings, lines etc.
    The reason I used perl is that I was under the impression it would be the fastest for the job but I never considered java. Now I am trying to get up to speed in Java so want to use these small jobs as practice?
    Thanks ... J

    Mod (Compiled) Perl is faster than Java I think. Also, perl has been optimized for this sort of thing. Plus, if you're creating a lot of small to medium size scripts, as you mentioned, perl will be a lot easier to support for you and who ever comes after you. Stick with what you know

Maybe you are looking for