當我使用:如何在正則表達式中反轉正向lookbehind(?<=)?
String s = "http://google.com, /home/roroco/Dropbox/jvs/ro-idea/META-INF/plugin.xml"
ArrayList<String> ms = s.findAll(/(?<=\/)\/\S+/)
println(ms)
輸出是:
[/google.com,]
當我更改爲:
s.findAll(/(?<!\/)\/\S+/)
輸出是:
[//google.com,, /home/roroco/Dropbox/jvs/ro-idea/META-INF/plugin.xml]
在我understandi ng,/(?<!\/)\/\S+/
輸出應該與/(?<=\b)\/\S+/
輸出相同,但事實上並非如此。爲什麼?
你有什麼需要得到什麼? '/(?<!\ /)\/\ S + /'!='/(?<= \ b)\/\ S + /'因爲'\ b'是一個字邊界, /'。 '(?<!\ /)'如果在'/'之前有'/',那麼匹配失敗。 –