This is the FAQ list for
#regex.
How do I parse HTML/XML?
How do I match a URL?
How do I match text which doesn't match a pattern?
How do I negate a match?
Ideally, you'll want to use the features of your language or application software to do this. Here are some examples:
Perl:
PHP:
sed:
vi:
mod_rewrite:
!/foo/
grep:
If you cannot use such a technique because your application (e.g. a text editor) does not allow that level of programmability, you may be able to get by with an expression such as:
Note however that this may be much slower than the equivalent negated expression.
How do I match text which contains words in any order?
How do I match text which matches more than one pattern?
This is another of those situations where regular expressions alone are not enough. The best way is to match the line against multiple patterns:
Perl:
if ($str =~
m/foo/ &&
$str =~
m/bar/
)
PHP:
sed:
grep:
Again, if you cannot use such a technique, try
There are no comments on this page. [Add comment]