Reputation: 13
How can I get the count of all instances of a regex?
This gives the expected result:
groovy> 'banana'.findAll(~/\wa/).size()
Result: 3
but this gives the same:
groovy> 'banaana'.findAll(~/\wa/).size()
Result: 3
How can I find all 'a's preceded by a letter, including another 'a'?
TIA
Brian
Upvotes: 1
Views: 60
Reputation: 174776
I think using lookbehind will give you the right output. Because lookarounds are zero length assertions. They do not consume characters in the string, but only assert whether a match is possible or not.
(?<=\w)a
Upvotes: 1