开发者

How can I translate this regular expression from Perl to Java?

开发者 https://www.devze.com 2023-03-31 16:54 出处:网络
Suppose, we need to match: Anything or nothing开发者_运维技巧, followed by a dot of which there may be 0 or 1,

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

精彩评论

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

关注公众号