1

How do we do regex matching in groovy, what will be the regex in groovy for below example?

Example : f2376 Regex: (anyLetter)(followed by 4 digits)
2

1 Answer 1

15

Pretty simple with groovy

"f1234" ==~ /[a-z]\d{4}/

Note that the regex [a-z]\d{4} means any of the characters a-z once, followed by exactly 4 digits, and can be probably be used with any language that handles regex, not just groovy.

In my console I tested for just lower case letters, but to handle upper case too just do

"f1234" ==~ /[a-zA-Z]\d{4}/

enter image description here

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

1 Comment

\w will match not only letters!

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.