开发者

Regular expression for a string that is not the prefix of some other particular string

开发者 https://www.devze.com 2023-03-10 01:31 出处:网络
What is the regular expression that woul开发者_运维知识库d find all instances of the string \"&\", but not if the instance is the prefix of the string \" \".

What is the regular expression that woul开发者_运维知识库d find all instances of the string "&", but not if the instance is the prefix of the string " ".

For example, it would match the "&" in "John & Paul", but not the "&" in "John   Paul".


What you're looking for is a negative lookahead (see this answer as well). The syntax would generally be something like:

&(?!nbsp;)

Which matches any ampersand not followed by nbsp;


Something like this may be :

\s&\s

You can try your regex on this website

0

精彩评论

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

关注公众号