0

I tried matching all letter-like characters within a string using /\p{L}/ig. However, this Unicode category doesn't seem to be supported by Nashorn's RegExp implementation.

Is there a workaround or fix for this?


Update: IMO this is not a duplicate of the referenced question: Nashorn 8 does implement ECMAScript 5.1, but since the engine runs on Java, there might be a "Java-way" to change the RegExp implementation used by the engine.


Update: I installed Java 9 (OpenJDK) which comes with Nashorn full version 9-internal+0-2016-04-14-195246. Even when running Nashorn with ECMAScript 6 (--language=es6), Unicode categories are not supported.

xpages-noob
  • 1,569
  • 1
  • 10
  • 37
  • 1
    Nashorn implements ECMAScript 5.1 (with some partial ES 6 features), and that spec does not define the \p assertion. As far as I can see, there currently is only a proposal for unicode property escapes in ECMAScript regex support, so I would not expect anything to be added to Nashorn in the near future. In those cases I typically just use the native Java Pattern + Matcher classes to work on my Strings. – Axel Faust Jan 01 '18 at 02:24
  • Thanks for the information. I know I could use Java's Pattern+Matcher, but I was hoping that there might be a solution that would allow me to keep using JavaScript's simple RegExp definition. For example, a Java option that allows to switch the RegExp implementation used by Nashorn. – xpages-noob Jan 01 '18 at 13:44

1 Answers1

2

As far as I can tell, Unicode Categories are not supported by current ECMAScript RegExp specifications (up to 6.0); e.g.

Nashorn is simply implementing the ECMAScript specifications. To do otherwise would be a bug!

If you really need support for Unicode Categories and other enhancements, consider changing your Javascript code to use the XRegExp library. Alternatively, call the native Java Pattern / Matcher classes from your Javascript code. Both approaches will require code changes ....

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for your answer and advice(s). I'll wait 1 or 2 days before accepting your answer to see if someone else might know about another quick fix. – xpages-noob Jan 01 '18 at 13:45