且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式匹配未跟随另一个特定字符的字符

更新时间:2023-02-17 23:40:53

虽然这似乎是一个坏主意,但我可以看到两种方法:

While this seems to be a bad idea, I can see two ways of doing it :

(<)(?:[^%])

[^] sequence允许您搜索除以下字符之外的任何内容。

The [^] sequence allows you to search for anything but the following character.

(?:)序列适用于非捕获组。

The (?:) sequence is for non capturing groups.

<(?!%)

(?!)序列如果与以下字符不匹配,则成功,但不是捕获。

The (?!) sequence succeeds if it doesn't match the following character, but is not captured.

(?:[^%])(>)

(小心这里,前瞻不会起作用,因为你需要向后看)

(careful here, the lookahead won't work as you need to go backwards)

(?<!%)>