我想寫一些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
除了斜槓'/'? –