How can I translate this regular expression from Perl to Java?
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
What's wrong with
^.*\\.?[Nn]etwork$
as in
boolean foundMatch = subjectString.matches("^.*\\.?[Nn]etwork$");
(The parentheses around the dot are unnecessary anyway).
精彩评论