Regexp in String.replaceAll() not working? [message #1844804] |
Sun, 26 September 2021 09:48 |
Maurizio M Gavioli Messages: 2 Registered: September 2021 |
Junior Member |
|
|
Hi,
I'm probably overlooking something very trivial but I seem unable to use regexp in search and replace in JS (Rhino) EASE scripts.
No regexp whatsoever seems to ever match, even regexps which work as intended with String.search() and/or very simple (and largely useless) regexps like /abc/g.
I have tried regexps directly in the statement:
txt = txt.replaceAll(/abc/g, 'cba');
defined previously as a literal:
var re = /abc/g;
txt = txt.replaceAll(re, 'cba');
or with the constructor:
var re = new RegExp('abc', 'g');
txt = txt.replaceAll(re, 'cba');
None of these does anything: txt is never altered. I have also tried without the global flag with no difference. This happens both within scripts and in the immediate interpreter. If the same regexp is used with String.search(re) it works as expected.
On the other hand, using String.replace() with a regular expression I get the following error:
org.eclipse.ease.ScriptExecutionException: SyntaxError: The choice of Java method java.lang.String.replace matching JavaScript argument types (function,string) is ambiguous; candidate methods are:
class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence)
class java.lang.String replace(char,char)
What am I doing wrong?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06276 seconds