David Portabella
David Portabella

Reputation: 12740

Use java regex in a Scala application

ScalaJs uses the javascript regexp library instead of the Java regexp library. Javascript regexp are a bit different, for instance they do not implement look-behind (?<=X).

How can I use the java regexp in a ScalaJs application? (in order to have the look-behind feature)


ps: I am aware that sometimes it's possible to simulate look-behind in javascript regexp, as shown here, and I am currently doing this. However, this question is about how to use java regexp in ScalaJs.

pss: I am also aware that there is a regexp external javascript library with look-behind, xregexp. Again, this question is about how to use java regexp in ScalaJs.

Upvotes: 1

Views: 80

Answers (1)

Justin du Coeur
Justin du Coeur

Reputation: 2659

Basically, you can't -- the Java Regexp, like most of the Java runtime environment, doesn't exist in the browser, so it doesn't exist for Scala.js. If you specifically need the Java Regex behavior, using one of those simulator libraries is probably your only option, at least for the time being.

As a rule of thumb, if something comes from the JRE, you should assume it does not exist in Scala.js unless someone has explicitly ported it. A growing amount has been ported, but it's still a fairly modest fraction of the total Java Runtime...

Upvotes: 1

Related Questions