acsadam0404
acsadam0404

Reputation: 2831

Groovy regexp doesn't work

Using groovy I want to match on the following: one word followed by a "." followed by a number.

assert 'randomword.[0-9]+' ==~ 'randomword.1'
assert 'randomword.[0-9]+' ==~ 'randomword.123'
assert 'randomword.[0-9]+' =~ 'randomword.1'
assert 'randomword.[0-9]+' =~ 'randomword.123'
assert 'randomword\\.[0-9]+' =~ 'randomword.1'

None of the above works, can someone explain me why and show me a way to do it right?

Upvotes: 2

Views: 90

Answers (1)

hwnd
hwnd

Reputation: 70722

The correct syntax would be:

assert 'randomword.123' =~ /randomword\.[0-9]+/

Upvotes: 3

Related Questions