1

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.

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

1 Comment

thx. I see in this doc what jre libraries can be used and which cannot, and how to port jre libs to ScalaJs. In our case, it is important to have the exact same regexp functionality both in backend and in frontend, but the cost of porting java regexp to scalajs might be too high for now. lihaoyi.com/hands-on-scala-js/#JavaAPIs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.