Are the regular Java and Groovy engines the same?

Now I am doing regex based code in Groovy. But for building and testing my regexes, I use the Java regex engine reference books http://www.regexplanet.com/advanced/java/index.html .

And I'm a little scared - is Groovy's regex engine really the same as Java's one? I know they are very close. But do they have any differences? If you know the answer - can you kindly give me a link to this topic?

+3


source to share


3 answers


From the language documentation :

The template operator (~) provides an easy way to create an instance java.util.regex.Pattern

.



I can't find an expression where the documentation guarantees that it is a regular expression engine used for pattern matching throughout Groovy; However, I find it very difficult, very, very unlikely that Groovy will use two RE engines in its implementation, or switch the RE engine in the future.

+4


source


"Since Groovy is Java based, you can use the Java regex package with Groovy. Just type import java.util.regex. * At the top of your Groovy source code. Any Java code using regex will automatically work in your Groovy code. . " Source: regular-expressions.info



+1


source


Here's a groovy example for regex matching along with find

:

assert ['abc'] == ['def', 'abc', '123'].findAll { it =~ /abc/ }

      

You can find more examples from here (including the example above), thanks to Mr. Haki.

0


source







All Articles