Reputation: 96391
Suppose, we need to match:
Anything or nothing, followed by a dot of which there may be 0 or 1, followed by the word "network", where N may come in lower case or upper case.
This works fine in Perl:
^.*(\.?)[Nn]etwork$
How would you match this in Java? I tried
(.*)\\.?(N|n)etwork$
but "blah.Network" does not match
Upvotes: 2
Views: 79
Reputation: 336148
What's wrong with
^.*\\.?[Nn]etwork$
as in
boolean foundMatch = subjectString.matches("^.*\\.?[Nn]etwork$");
(The parentheses around the dot are unnecessary anyway).
Upvotes: 1