konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.66k stars 265 forks source link

Are named capture groups supported by TeaVM when using java.util.regex.Pattern? #952

Open jakrous opened 2 months ago

jakrous commented 2 months ago

My Java implementation using java.util.regex.Pattern is able to process a regex with a named capture group such as "(?<year>\\d{4})" however when I attempt to pass this regex to the JSExport-ed JavaScript function, I am met with an error without additional context.

For added context, I have a simple Java function named findMatches. This function performs a straightforward regex test and returns the list of matches. I've annotated this function with @JSExport and use the resulting JavaScript file in my React app. Unnamed capture groups and other regular expressions are processed without issue. Named capture groups unfortunately fail.

Is there a limitation within TeaVm that may be causing this?

konsoletyper commented 2 months ago

Yes, there are some limitations of regexes in TeaVM. The regex engine was itself taken from Harmony, which stuck at Java 7. Although I constantly improve some parts of Java standard library to fit latest Java specs, with regex I never had a chance to make improvements (and I doubt if have one in observable future).