Ankur
Ankur

Reputation: 148

meaning of this regex expression

Can anybody tell me what does this regular expression identifies : (?![^&;]+;)(?!<[^<>]*) and (?![^<>]*>)(?![^&;]+;).

Thanks.

Upvotes: 2

Views: 178

Answers (1)

FailedDev
FailedDev

Reputation: 26930

First one :

"
(?!         # 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)
)
"

Second one :

"
(?!         # 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
)
"

Note that both of those expressions do not actually capture anything at all but they are probably used to pinpoint a position inside the string. Without any context is hard to tell exactly where they are used.

Upvotes: 5

Related Questions