问题
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)
回答1:
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}/
来源:https://stackoverflow.com/questions/7772497/groovy-regex-pattern-matching