Crimson 的答案不适用于我在Regex Powertoy中使用<Escaped characters \<\> are right in the middle of this sentence.>, <Here is another sentence.>
作为测试的测试,但这(似乎)有效:
/<(?<!\\<).*?>(?<!\\>)/gi
给了我两场比赛:
<Escaped characters \<\> are right in the middle of this sentence.>
和<Here is another sentence.>
编辑:我看了看 Gumbo 说的字符串不匹配。我在 regex.powertoy.org 中匹配它没有任何问题:
替代文字 http://img362.imageshack.us/img362/3227/regexpowertoyorg.png
在测试中,我确实将原始发布的正则表达式更改为:/(?<!\\)<(.*?)(?<!\\)>/gi
更有效(更少的探测)。
我还注意到在 regex.powertoy.org 的输出中,第四个字符串 ( \<hello <match\<this\>> but not this\> looks odd... the printed replacement is just
match but the match detail clearly shows that the match is correct;
match\ . But I also notices that the first and third test string replacements don't print the "
`" 转义了尖括号。经过一段时间(但不是详尽)玩耍后,我认为这是文本显示的问题通过javascript,转义的尖括号不打印转义字符,并且根本不打印非空尖括号。我认为这是由于javascript将其视为HTML。所以;我认为这个正则表达式正在工作正确。但你应该离线测试它。