Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are regex engines of Java and Groovy the same?

Tags:

java

regex

groovy

Now I am doing some code basing on regex in Groovy. But for creation and testing my regexes I use books referencing to Java regex engine and Java-oriented http://www.regexplanet.com/advanced/java/index.html.

And I am a bit afraid - Is Groovy regex engine really the same as Java one? I know that they are very close. But have they some differences nevertheless? If you know the answer - can you kindly give me some reference on the subject?

like image 231
Gangnus Avatar asked Dec 08 '25 13:12

Gangnus


2 Answers

From the language documentation:

The pattern operator (~) provides a simple way to create a java.util.regex.Pattern instance.

I can't find phrasing where the documentation guarantees this is the regular expression engine used for pattern matching throughout Groovy; I do however find it very, very, very, very unlikely Groovy would use two RE engines in its implementation now or switch the RE engine in the future.

like image 188
millimoose Avatar answered Dec 11 '25 03:12

millimoose


"Because Groovy is based on Java, you can use Java's regular expression package with Groovy. Simply put import java.util.regex.* at the top of your Groovy source code. Any Java code using regular expressions will then automatically work in your Groovy code too." Source: regular-expressions.info

like image 44
Kevin H. Avatar answered Dec 11 '25 03:12

Kevin H.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!