Regular Expression - [^abc] - matches a character other than a or b or c

The square brackets and circumflex ([^]) match with any single character that is not contained in the brackets.

Examples

Match an HTML tag - if you use .* in the regular expression, you would match from the opening of the first tag to the closing of the last tag in the line. Instead the following expression ensures it only matches characters between the tags that are not a close tag:

<[^>]+>
This would match the following:
<a href="http://www.homemarketeer.com">
It would not match the following:
<<<
It would only match the tags in the following:
<a href="http://www.homemarketeer.com">HomeMarketeer</a>

Computing Articles