我想写一些patttern的正则表达式。正则表达式匹配模式,除了它的一些字符串
/web/surfer* --Match
/web/surfer/information* --Not Match
有没有人告诉我们该如何写正则表达式来匹配这个在Java中
我想写一些patttern的正则表达式。正则表达式匹配模式,除了它的一些字符串
/web/surfer* --Match
/web/surfer/information* --Not Match
有没有人告诉我们该如何写正则表达式来匹配这个在Java中
我相信你正在寻找这样的正则表达式负前瞻:
/web/surfer(?!/information).*
试试这个例子:
String s = "/web/surfer/information";
System.out.println(s.matches("/web/surfer(?!/information).*"));
你可以试试这个:
^/web/surfer(?>[^i]++|\\Bi|i(?!nformation\\b))*$
我觉得困惑是你用*来匹配任何文本,而你实际上需要一个点。
这会有帮助吗?
String regex = "/web/surfer.*";
System.out.println("/web/surfer*".matches(regex)); // prints true
System.out.println("/web/surfer/information*".matches(regex)); // prints true
'*'表示什么? –
@CasimiretHippolyte。这里*表示任何文本。 – Patan
除了斜杠'/'? –