Regex negative lookahead

南笙酒味 提交于 2019-12-23 09:59:07

问题


I need to modify this regex

href=\"(.*)\"

which matches this...

href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306"

To NOT match this...

href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306&returnurl=AbandonedVehicles.aspx"

Tried this, but with no luck

href=\"(.*)\"(?!&returnurl=AbandonedVehicles.aspx)

Any help would be much appreciated.

Thanks, Al.


回答1:


Lookaheads should be placed before the string is consumed by matching, i.e.

href=\"(?!.*&returnurl=AbandonedVehicles\.aspx)(.*)\"



回答2:


href="(?!.*returnurl=AbandonedVehicles\.aspx)(.*)"


来源:https://stackoverflow.com/questions/2646213/regex-negative-lookahead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!