这个正则表达式的含义

时间:2011-11-05 00:19:29

标签: regex

有人可以告诉我这个正则表达式标识了什么:(?![^&;]+;)(?!<[^<>]*)(?![^<>]*>)(?![^&;]+;)

感谢。

1 个答案:

答案 0 :(得分:5)

第一个:

"
(?!         # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
   [^&;]       # Match a single character NOT present in the list “&;”
      +           # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
   ;           # Match the character “;” literally
)
(?!         # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
   <           # Match the character “<” literally
   [^<>]       # Match a single character NOT present in the list “<>”
      *           # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
)
"

第二个:

"
(?!         # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
   [^<>]       # Match a single character NOT present in the list “<>”
      *           # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
   >           # Match the character “>” literally
)
(?!         # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
   [^&;]       # Match a single character NOT present in the list “&;”
      +           # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
   ;           # Match the character “;” literally
)
"

请注意,这两个表达式实际上并没有捕获任何内容,但它们可能用于精确定位字符串中的位置。没有任何上下文很难准确说明它们的使用位置。