Skip to content
Advertisement

Java equivalent of this JavaScript regex code?

I have this JavaScript code:

JavaScript

I am trying to find the Java equivalent. I’ve tried the following bit it gives a different result:

JavaScript

Any help is much appreciated!

Advertisement

Answer

The problem you are having is that '\$&' is Javascript mean whole matched string but doesn’t mean the same in Java. I don’t think there is a one-line solution in Java to solve this problem, but this code should work:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement