How would I make a regular expression to match the character '<' not followed by ('a' or 'em' or 'strong')
so <hello and <string would match, but <strong wouldn't.
UPDATE: Btw, the language I'm using is javascript
How would I make a regular expression to match the character '<' not followed by ('a' or 'em' or 'strong')
so <hello and <string would match, but <strong wouldn't.
UPDATE: Btw, the language I'm using is javascript
You use a negative lookahead, the simplest form for which is (for this problem):
<(?|a|em|strong)
The one issue with that is that it will ignore <applet>. The way you deal with that is by using \b, which is a zero-width expression (meaning it captures none of the input) that matches a word to non-word or non-word to word transition. Word characters are [0-9a-zA-Z_]. So:
<(?|(a|em|strong)\b)
If your regex engine supports it, use a negative lookahead assertion: this looks ahead in the string, and succeeds if it wouldn't match; however, it doesn't consume any input. Thus, you want /<(?!(?:a|em|strong)\b)/: match a <, then succeed if there isn't an a, em, or strong followed by a word break, \b.