Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Rhino, Regular Expression and Java \r\n

800429Jul 8 2009 — edited Jul 9 2009
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 for
So 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2009
Added on Jul 8 2009
3 comments
855 views