Java parser for regular expression to java program

Hi All,
I am very new to parser technologies .I am looking for a (java)parser which can read the "regular expression" and can convert it into "java program".Please let me know is there any thing related to this.
Thanks in advance.
Your will be appriciate.
Regards,
Sai.

Hi Jos,
Thank you for your quick response .You're welcome.
If you have any sample code or simple example for how to use those
classes (Pattern,Match) ,will you please send me .It will be helpful for me.Jverd gave you two nice links already in his reply #3
If there is any "open source" for parsering regular expressions.
Please send me I am very new to parser technologies.Note that that Pattern class take care of all the parsing of REs, i.e. there's
nothing 'interesting' left for you to do any parsing whatsoever. Can you
elaborate a bit on what you exactly want to do and learn?
kind regards,
Jos

Similar Messages

  • Using regular expressions in java

    Does anyone of you know a good source or a tutorial for using regular expressions in java.
    I just want to look at some examples....
    Thanks

    thanks a lot... i have one more query
    Boundary matchers
    ^      The beginning of a line
    $      The end of a line
    \b      A word boundary
    \B      A non-word boundary
    \A      The beginning of the input
    \G      The end of the previous match
    \Z      The end of the input but for the final terminator, if any
    \z      The end of the input
    if i want to use the $ for comparing with string(text) then how can i use it.
    Eg if it is $120 i got a hit
    but if its other than that if should not hit.

  • Regular expression in java -- specifically email

    Does anyone know how I can do a regular expression with java that is going to retrieve an email address pattern.
    For example, let's say i have a huge string
    this is a sample test. perhaps someoen can tell me how to retrieve my [email protected] from this string. sincerely yours [email protected]
    could someone explain to me how to retrieve these emai addresses most efficiently using java's regular expressions
    thanks
    stev

    A citing (http://jregex.sourceforge.net/examples-email.html):
    String someValidChars="[\\w.\\-]+";
    String someAlphaNums="\\w+";
    String dot="\\.";
    Pattern email=new Pattern(someValidChars + "@" + someValidChars + dot + someAlphaNums);

  • Can somebody help me in getting some good material for Regular Expressions and IP Community list

    can somebody help me in getting some good material for Regular Expressions and IP Community list

    I'm not sure what you mean by "IP Community list", but here are 3 reference sites for Regular Expressions:
    Regular Expression Tutorial - Learn How to Use Regular Expressions
    http://www.regular-expressions.info/tutorial.html
    Regular Expressions Cheat Sheet by DaveChild
    http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
    Regular Expressions Quick Reference
    http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm

  • Does it give any java parser for java programming guidelines?

    i've got a parser for c/c++ programs (codecheck from abraxas) from 1996, i think. but i didn't find anyone for java. does anyone know where from i'm able to download one?

    http://www.experimentalstuff.com/Technologies/JavaCC/

  • Validation for regular expressions special characters in java

    Hi,
    I need to validate an user name field to an application while creating that. It has to contain only alpha numerics. can you give me the regular expression and also how to implement that.
    thanks,
    VJ

    Do your own work. Look up the documentation on Pattern and make an attempt at validating a String yourself. Then worry about implementing a GUI on top of that.

  • Regular Expressions with Java Regex

    Hi,
    I'm playing around with regex and there's something I can't get to work. What I need, is to capture words between 2 other words and the words captured has to be higher than 5 characters, so for example:
    Pattern "Just testing on something with regular expressions" and suppose I'll try to match all the words between "testing" and "regular", then only the word "something" should come out because "on" and "with" are not larger than 5 chars.
    Now I'm quite new to regexps and I know that ((?<=\btesting\b).*(?=\bregular\b)) will return " on something with "
    But I can't seem to come up with an expression that would only output the word "something". I've tried a few expressions like ((?<=\btesting\b)((?:[\s\w{1,3}])*(\b\w{4,}\b)*(?:[\s\w{1,3}])*)*(?=\bregular\b)) which also returns " on something with " The others I tried would either return the whole " on something with " or return "Not Found!"
    Does anyone have a tip for me? I'm well aware that it's not too hard to do something like this in Java, but I'm really looking to study regular expressions and would like to accomplish this using a regular expression.
    The Java program I use is the following:
    C:\Program Files\Java\jdk1.5.0_16\bin>java RegexTest "((?<=\btesting\b).*(?=\bregular\b))" "Just testing on something with regular expressions"
    public class RegexTest {
         public static void main(String[] args) {
              Pattern RegexCompile = Pattern.compile(args[0]);
              Matcher m = RegexCompile.matcher(args[1]);
              boolean found = m.find(); // Perhaps there's another function to find () that would do the job?
              if (found)
              System.out.println(m.group()); // Perhaps group() is not the right function for this case?
              else
              System.out.println("Not Found!");
    Edited by: dli2k3 on Sep 19, 2008 11:32 AM
    Edited by: dli2k3 on Sep 19, 2008 11:33 AM

    You're talking about a two-stage operation: find everything between those two words, then filter out anything that's less than five letters long. There's no single regex that will accomplish all that in one step.
    By the way, please use &#x7B;code} tags when you post source code.

  • "Stupid design of regular expression in java"

    I bet majority will stumble on this:
    String inputStr = "a,,b";
    String patternStr = ",";
    String[] fields = inputStr.split(patternStr);
    result: ["a", "", "c"]
    so if inputStr = ,,
    then result: ["","",""] ??
    If you think so, give yourself a treat.
    Now give yourself a bigger treat. cause
    the result is [""]
    Unbelievable about inconsistency of regular expression.
    It look so irregular.

    Take a look at the site which quote
    http://www.devarticles.com/c/a/Java/Regular-Expressions/10/
    Perl is probably the most popular language to offer regular expression support. As such, it makes sense to put Java&#8217;s regex support in context by comparing it to that of Perl. The distinctions you should be aware of are highlighted in the sections that follow. Generally speaking, J2SE doesn&#8217;t include some Perl constructs, because Java is a full-featured programming language that offers sophisticated condition and logical paths of execution that are reasonable alternatives to the constructs offered by Perl."
    Since, Java doesn't offer means it is perl, why not fix the "weirdness" of perl is in this case ? let the split function work as intended.
    Check this out from Java almanac
    // Parse a comma-separated string
    String inputStr = "a,,b";
    String patternStr = ",";
    String[] fields = inputStr.split(patternStr);
    // ["a", "", "b"]
    // Parse a line whose separator is a comma followed by a space
    inputStr = "a, b, c,d";
    patternStr = ", ";
    fields = inputStr.split(patternStr, -1);
    // ["a", "b", "c,d"]
    // Parse a line with and's and or's
    inputStr = "a, b, and c";
    patternStr = "[, ]+(and|or)*[, ]*";
    fields = inputStr.split(patternStr, -1);
    // ["a", "b", "c"]
    Everything is mentions except to solve the common issue I have.
    http://javaalmanac.com/egs/java.util.regex/ParseLine.html
    The above will failed if any empty data within pipe. It is how you manage to detect the empty data that is relatively important because it screw up your program. And too code to do that increase your chance of program error.
    Sometimes we just accept thing but never question why there aren't better way.

  • Java Built-in regular expressions versus Jakarta

    Are there any advantages to using the Jakarta regular expression package, over the built-in Java regular expressions?
    I wasn't able to find much information on the Jakarta regexp package, except for the Javadoc and I didn't find that very informative.
    Thanks!
    Jeff

    Well, the String.replaceAll(String, String) method uses the Java regexp internally, and I'm not sure there's a way to change that. So that at least is one place that will use it. I don't know for sure, but Jakarta's ORO is supposed to be fully compatible with Perl 5, and also supports other regexp types as well, so if you need that aspect of it, then go with Jakarta. I heard some of Java's are a little limited in some capabilities. I can't find any particular pages that refer to any comparisons of them at to compare runtime performance.

  • Using regular expressions in Java SE v1.3.1

    Hi,
    I have made a package in which I use the regular expressions package in J2SE v1.4. Unfortunately it turned out that my users are only using v1.3. I wonder if it is somehow possible to import the regexp package in v1.3?
    Kind regards
    Jesper

    Sorry No you cant use 1.4.1 RE in 1.3.1
    3 ways of getting round this
    1)
    have 2 diff jar Files, one for 1.3.1 and one for 1.4.1
    2)
    use a seperate RE package
    such as the Java RE package (before it was added in 1.4.1)
    or apache's regexp (This is what I do) from
    http://jakarta.apache.org/regexp/index.html
    3)
    tell your users to update to 1.4.1 !!

  • Oracle Regular Expressions in Java?

    JDEV 10.1.3
    ADF BC
    ADF Faces
    Is there a Java library for dealing with Oracle regular expressions? I would like to be able to test a String against an Oracle regular expression for pattern match.
    Thank you,

    Hi,
    Java supports RegularEpressions: http://www.exampledepot.com/egs/java.util.regex/pkg.html
    Frank

  • 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

  • Can I use regular expressions in Java 1.3

    Hi,
    Dose Java 1.3 suport regular expressions?
    How can I use it?
    Thanks.
    bevin ye

    The 1.3 core API doesn't support regular expressions. Hint: There's an item "Since:" in the JavaDoc of most classes that indicates the version it was initially available. If you look it up in the JavaDoc of java.util.regex.Pattern you'll notice that it's value is 1.4.
    But there are several third party libraries that implement regular expressions, 'though I've not used them extensivly, so I can't tell you which one's the most usefull.

  • Regular Expression in Java problem

    what is wrong with the following regex?
    query = query.replaceAll("SELECT.*?([WHERE.*?|GROUP BY.*?|HAVING.*?|ORDER BY.*?|LIMIT.*?]*?)","\\1");
    when I put in this:
    "SELECT WHERE MlsNumber=\'555555\', AdType=\'MyAdType\'"
    I get this:
    "1 WHERE MlsNumber='5100093', AdType='NytClass'"
    Where is the 1 coming from? I know the backreference must be working or I wouldnt get the WHERE statement back.

    There's a pretty good regex tutorial at this site: http://www.regular-expressions.info/ (I meant to include that in my first reply).
    Basically what I'm trying to do is cut the SELECT and
    anything after it up until it reaches the WHERE (and
    text), GROUPBY, HAVING, ORDER BY, or LIMIT. I want to
    remove The SELECT and text, but keep all instances of
    WHERE text GROUP BY text, etc. I also want to
    keep anything that is past then end of these
    expressions (in case there are option I haven't
    forseen).Try this:  query = query.replaceFirst("SELECT.*?(?=WHERE|GROUP BY|HAVING|ORDER BY|LIMIT)", "");The (?=...) part is a lookahead; it will cause the .*? to stop matching at the first instance of "WHERE", "GROUP BY", "HAVING", "ORDER BY", or "LIMIT". (Check out the "Lookahead & Lookbehind" section in the tutorial for an explanation.) However, if the first thing after the SELECT clause is one of the unknown options you mentioned, it will be removed too. If you know that keywords will always be in all caps, and that none of the other text will be, you could try generalizing the regex like this:  query = query.replaceFirst("SELECT.*? (?=[A-Z]{3,})", "");This regex assumes that any sequence of three or more capital letters preceded by a space is a keyword, which is probably not a safe assumption, but it gives you an idea of the kind of thing you can try.
    I thought the brackets were there to allow you to
    select choices from a group of items, if not I can
    remove them.Alternation doesn't require special bracketing characters. You usually want to enclose it in parentheses, but that's just to isolate it from the rest of the regex (e.g., "abc(?:foo|bar)xyz"). Square brackets are used for character classes, which are a completely different breed of animal; look them up in the tutorial.
    Apparantly the JDK docs are wrong, since they tell you
    to use the \\1 instead of $1 (which works).If you want to use a backreference within the regex, you use \1. For instance, if you want to match a complete HTML element, you might use  String regex = "<(\\w+)[^>]*>.*?</\\1>";But in the replacement string, you use $1. BTW, it's the Matcher docs that tell you that, not the Pattern docs.

  • Rhino, Regular Expression and Java \r\n

    Hi guys,
    I have an application that allow the user to create some regex to compare values by using scripting, basically I am using the test code
            ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr.getEngineByName("rhino");
            String[] scripts = {"/[abc]+/.test(\"giscaaard\")",
                                      "/[abc]+/.test(\"giscaaard\r\")"};                           
            for(String script : scripts){
                Object result = engine.eval(script);
                System.out.println(script + ":" + result);
            }//end forSo I run a simple test
    The output is
    /[abc]+/.test("giscaaard"):true
    Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: unterminated string literal (<Unknown source>#1) in <Unknown source> at line number 1
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
    at threads.Threads.main(Threads.java:34)
    Java Result: 1
    Any idea why rhino doesn't accept \r\n? If there is a standard for this where I can get how it handles other characters?
    PS: In fact my first idea was to use only java classes for perform such things, however when I try to importClass(java.lang.String) I get an exception saying rhino already has one. Is there anyway on how I can give up rhino default classes and use the java one?
    Thanks and Regards

    Hi guys,
    I just figure out something else
    The code:
    ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr.getEngineByName("rhino");
            String[] scripts = {/*"\"giscard\" == \"giscard\"",
                                "\"giscard\" == \"giscard\"",
                                "\"gff\" < \"giscard\"",
                                "\"gff\" > \"giscard\"",
                                "5 == 1",
                                "27 > 9",*/
                                "'Giscard'\n'SecondLine'",
                                "\"Giscard\tFaria\"",
                                "'Giscard\tFaria'",
                                "'Giscard\nFaria'"
            for(String script : scripts){
                Object result = engine.eval(script);
                System.out.println(script + ":" + result);
            }//end forGives the output
    'Giscard'
    'SecondLine':SecondLine
    "Giscard Faria":Giscard Faria
    'Giscard Faria':Giscard Faria
    Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: unterminated string literal (<Unknown source>#1) in <Unknown source> at line number 1
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
    at threads.Threads.main(Threads.java:36)
    Java Result: 1
    So, the \r\n has nothing to do with regex, it seems that javascript doesn't support string variables that has the \r \n inside it, however other special characters like \t are supported. Any idea on how to handle that?
    Regards

Maybe you are looking for

  • Loading data to a cube

    Hi All, We have created one cube and loaded data successfully. But we have one dimension named periodType: the members of the period are:Annual, Quarterly and Monthly. Client asked to make Monthly as + and remaining ~. For that we have created one vi

  • DMS:Original file path overriding configuration ?

    Hi, Running 4.6c. We use vault method for originals. We have configured data carrier type "Server,frontend" -> PC and are maintaining a path as c:\ for the temporary files. We also have configured 'frontend computers' by putting in the entry as 'Defa

  • Run time error while creating sales order in VA01

    Dear all, In our develpment server(ecc 6.0),while creating sales order in VA01 for a sales area, when ever entering material number and quantity and press enter, it is giving error and taking to Runtime error long text showing syntax error in program

  • WF Copy from ECC 6.0 system to 4.6 system - sww_wi2obj

    Hi, We are trying to copy a work flow objects from ECC6.0 to 4.6C...where we found the following Select statement. *Determine Top WorkItem Instance if im_top_wi_id is initial. select wi_id top_wi_id wi_rh_task into lw_top_id from sww_wi2obj up to 1 r

  • Duplicated/blurred/overlapping fonted text in web view

    We are experiencing an annoying issue with fonted text in web view frames. See the screenshot below: Look closely at the headline and you'll notice that it seems to be duplicated on top of itself, as if there are two identical headlines on top of eac