开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜