"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’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’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.

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 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.

  • 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

  • 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.

  • 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

  • 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

  • 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.

  • Regular expressions with java.util.regex

    Hello Guys,
    I wrote last time this
    * Uses split to break up a string of input separated by
    * commas and/or whitespace.
    * See: http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/
    * Change: I have slightly modified the source
    import java.util.regex.*;
    public class Splitter {
    public static void main(String[] args) throws Exception {
    // Create a pattern to match breaks
    Pattern p = Pattern.compile("[<>\\s]+");
    // Split input with the pattern
    String[] result =
    p.split("<element attributname1 = \"attributwert1\" attributname2 = \"attributwert2\">");
    for (int i=0; i<result.length; i++)
    if (result.equals(""))
    System.out.println("EMPTY");
    else
    System.out.println(result[i]);
    int res = result.length - 1;
    System.out.println("\nStringlaenge: " + res);
    I wonder, why I got an empty element in reult[0]. Have anyone an idea?
    We'll come together next time
    ... �nhan Inay ([email protected])

    What is wrong with this Pattern?
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    This time i used following Split:
    p.split("<element attributname1=\"attributwert1\" attributname2=\"attributwert2\">");
    I've got a compilation error:
    U:\qms_neu\htdocs\inay\Source\myWork\Regex-Samples>javac Splitter.java
    Splitter.java:14: illegal start of expression
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: illegal character: \92
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: illegal character: \92
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: unclosed string literal
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:17: ')' expected
    p.split("<element attributname1=\"attributwert1\" attributname2
    =\"attributwert2\">");
    ^
    Splitter.java:14: unexpected type
    required: variable
    found : value
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:18: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    for (int i=0; i<result.length; i++)
    ^
    Splitter.java:19: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    if (result.equals("")){
    ^
    Splitter.java:21: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    System.out.println(result[0]);
    ^
    Splitter.java:24: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    System.out.println(result[i]);
    ^
    Splitter.java:25: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    int res = result.length - 1;
    ^
    11 errors

  • Regular Expressions in Java?

    I have written pattern matching in perl such as
    if($name =~ /^(test)(.+)$/o){
    $drop = $2;
    Basically it looks like test1.8.8, test1.0.3, etc.
    What would be the equivalent of this in java?

    static final Pattern p = Pattern.compile("^(test)(.+)$");
        Matcher m = p.matcher(name);
        if (m.matches()) {
            drop = m.group(2);
        }You used the /o flag, which tells perl to only compile the regex once. The java.util.regex package doesn't have any equivalent for that flag, but you can get the same effect by pre-compiling the regex and storing it in a class or instance field, as I did here.

  • Regular expression in java

    Say I have a string:
    44503013 20 36 57.611 -32 11 41.26 309.240046 -32.194794 708 324    18.1   -23.3  7.7  7.7 15.64 18.13  2.49210 40   2  1  1  K  is there a library provided in java where I can extract/parse the first 8 digits found in this string? so therefore the result I get will be
    44503013

    Encephalopathic wrote:
    sneaky. That stimulates me to write a translation program so I too can solve homework problems and post them here.
    You mean like this?
    \u0069\u006d\u0070\u006f\u0072\u0074 \u006a\u0061\u0076\u0061\u002e\u0069\u006f\u002e\u0046\u0069\u006c\u0065\u0052\u0065\u0061\u0064\u0065\u0072\u003b
    \u0069\u006d\u0070\u006f\u0072\u0074 \u006a\u0061\u0076\u0061\u002e\u0069\u006f\u002e\u0052\u0065\u0061\u0064\u0065\u0072\u003b
    \u0070\u0075\u0062\u006c\u0069\u0063 \u0063\u006c\u0061\u0073\u0073 \u0053\u0061\u0062\u0072\u0065\u0032\u0030\u0030\u0039\u0030\u0039\u0030\u0037\u0061
    \u007b
        \u0070\u0075\u0062\u006c\u0069\u0063 \u0073\u0074\u0061\u0074\u0069\u0063 \u0076\u006f\u0069\u0064 \u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d \u0061\u0072\u0067\u0073\u0029 \u0074\u0068\u0072\u006f\u0077\u0073 \u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e
        \u007b
            \u0052\u0065\u0061\u0064\u0065\u0072 \u0072 \u003d \u006e\u0065\u0077 \u0046\u0069\u006c\u0065\u0052\u0065\u0061\u0064\u0065\u0072\u0028\u0061\u0072\u0067\u0073\u005b\u0030\u005d\u0029\u003b
            \u0066\u006f\u0072 \u0028\u0069\u006e\u0074 \u0063\u0068\u003b \u0028\u0063\u0068 \u003d \u0072\u002e\u0072\u0065\u0061\u0064\u0028\u0029\u0029 \u0021\u003d \u002d\u0031\u003b\u0029
            \u007b
                \u0069\u0066 \u0028\u0063\u0068 \u003d\u003d \u0027\u005c\u006e\u0027\u0029
                    \u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0029\u003b
                \u0065\u006c\u0073\u0065 \u0069\u0066 \u0028\u0063\u0068 \u003d\u003d \u0027 \u0027\u0029
                    \u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u0028\u0027 \u0027\u0029\u003b
                \u0065\u006c\u0073\u0065
                    \u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u0066\u0028\u0022\u005c\u005c\u0075\u0025\u0030\u0034\u0078\u0022\u002c \u0028\u0069\u006e\u0074\u0029 \u0063\u0068\u0029\u003b
            \u007d
        \u007d
    \u007d

  • 3 regular expression and java crash WHY?? / HOW to SOLVE IT?

    Hi, i hava problem on my program there is 3 regex after another.
    The JAVA crash down idona know why
    want to solve it how i think i have to clear the regex so they not be in the memory after proccessing
    help needed >> Please

    asfdal-qsa wrote:
    contents = contents.replaceAll("(?i)(<\\s*\\w*[^>]*?>((?:.*?\\s*?)+)<\\s*?/\\s*?\\w*\\s*?>)", " ");if i use replaceAll or not it is the same output
    Java crash down and give me this
    Exception in thread "main" java.lang.StackOverflowError
    at java.util.regex.Pattern$Curly.match(Pattern.java:3746)
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
    at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
    at java.util.regex.Pattern$Curly.match1(Pattern.java:3797)
    at java.util.regex.Pattern$Curly.match(Pattern.java:3746)
    at java.util.regex.Pattern$Curly.match1(Pattern.java:3797)
    at java.util.regex.Pattern$Curly.match(Pattern.java:3746)
    and still continue
    Edited by: asfdal-qsa on Apr 12, 2009 7:14 AMWhat's wrong with my suggestion:
    "<[^<>]++>"?

  • 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

  • Sound no longer works after upgrade to Windows 8.1

    System: Operating System Windows 8.1 64-bit CPU Intel Core i5 3330 @ 3.00GHz 23 °C Ivy Bridge 22nm Technology RAM 8.00GB Dual-Channel DDR3 (11-11-11-28) Motherboard LENOVO MAHOBAY (SOCKET 0) 18 °C Audio ASUS Xonar DGX Audio Device I sucessfully upgra

  • Tutor 14 - publisher error

    I've recently moved from Tutor 11i to Tutor 14, however I am not able to publish in Tutor 14. I can open Publisher with no problems but when I select File > Publish, the whole application shuts down! I've done the following checks: - ensured there we

  • PC-CAM 600, freezes when taking regular camera pictures - too dark

    I just started having this problem. I'll take a picture and it freezes and won't even let me shut the camera off. When it actually does take a picture - in plenty of light or with the flash inside, the pictures are so dark i can't make them out. When

  • Upload / download of files

    Dear Friends, I know that the question will probably be redundant to you all but here it goes: how do I go about uploading a file for download from my site. ( in this case a PDF ). I suspect that it has to go in a ftp public folder but don't have a c

  • Need Help With Videos on Zen V P

    I need help putting videos on my Creative Zen V Plus. I convert them to avi using Super Converter and I drag and drop them into the folder for the videos on my zen. When I turn on my Zen and go to the videos the video is there however when I try to p