Original Post
🔒 Locked
Regular Expressions Question
Advertisement
The first matches "&" when it is followed by not ("amp;" or "nbsp;").
The second matches "&" when it is followed by (not "amp;") or (not "nbsp;").
That means the second will match every "&", because it's impossible to be followed by both "amp;" and by "nbsp;" - it will always succeed either the 'not followed by "amp;"' or the 'not followed by "nbsp;"' test (or both), and the '|' just means the whole expression will match if either of those cases matches. So it's equivalent to /&/g, which isn't very useful, whereas the first will correctly match any "&" that isn't part of " " or "&".
The second matches "&" when it is followed by (not "amp;") or (not "nbsp;").
That means the second will match every "&", because it's impossible to be followed by both "amp;" and by "nbsp;" - it will always succeed either the 'not followed by "amp;"' or the 'not followed by "nbsp;"' test (or both), and the '|' just means the whole expression will match if either of those cases matches. So it's equivalent to /&/g, which isn't very useful, whereas the first will correctly match any "&" that isn't part of " " or "&".
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement