matcher.maches() returns false
Why this code fails ?
Because of you think you do something like "Oh dear it contains the word!", but you're confusing matches with find
public boolean matches()
Attempts to match the entire region against the pattern.
So "/\.groovy/" is just a subsequence.
You must use
What is the difference between =~ and ==~ ?
Pattern, Matcher ?
A pattern is not very usefull alone. He's just waiting input to process through a matcher.
Matcher can say a lot of thing to you:
- if the entire input sequence matches the pattern, with
- if a just subsequence of the input sequence matches the pattern with,
A matcher with /groovy/ pattern finds a matching subsequence in the 'my groovy buddy' sequence.
On the contrary the whole sequence doesn't match the pattern.
Application: to filter a list of names.
A little tilde headache ? Remember like this
roughly as the pattern (easy to write)
more than roughly, exactly as the pattern (think hard...)