Other Examples |
Top Previous |
AND
Although the regular expression engine does not directly support the concept of the boolean AND operation it can, in a limited way, be simulated. e.g.
To search for a line containing 'error' AND 'log' the expression would be '(error.*log)|(log.*error)'. Basically the different possible combinations have been combined, i.e. find 'error' followed by 'log' OR find 'log' followed by 'error'. While this works for a small number of words it does become infeasible with a larger number of words.
Obviously the simplest way to specify an AND style expression is to use the Boolean expression engine.
Email addresses
Regular expressions are great for validating or searching for patterns such as email addresses. The following regular expression should match most email addresses:
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
|