%META:TOPICINFO{author="ProjectContributor" date="1277543304" format="1.1" version="1"}%
%META:TOPICPARENT{name="UserDocumentationCategory"}%
---+!! Regular Expressions

%TOC%
---++ Introduction

Regular expressions (REs), unlike simple queries, allow you to search for text which matches a particular pattern.

REs are similar to (but much more powerful than) the "wildcards" used in the command-line interfaces found in operating systems such as Unix and MS-DOS. REs are supported by sophisticated search engines, as well as by many Unix-based languages and tools ( e.g., =awk=, =grep=, =lex=, =perl=, and =sed= ).

---++ Examples

| =compan(y&#124;ies)= | Search for *company* _or_ *companies* |
| =(peter&#124;paul)= | Search for *peter* _or_ *paul* |
| =bug*= | Search for *bug*, *bugg*, *buggg* or simply *bu* (a star matches *zero* or more instances of the previous character) |
| =bug.*= | Search for *bug*, *bugs*, *bugfix* (a dot-star matches zero or more instances of *any* character) |
| =[Bb]ag= | Search for *Bag*, *bag* |
| =b[aiueo]g= | Second letter is a vowel. Matches *bag*, *bug*, *big* |
| =b.g= | Second letter is any letter. Matches also *b&amp;g* |
| =[a-zA-Z]= | Matches any one letter (but not a number or a symbol) |
| =[^0-9a-zA-Z]= | Matches any symbol (but not a number or a letter) |
| =[A-Z][A-Z]*= | Matches one or more uppercase letters |
| =[0-9]{3}-[0-9]{2}-[0-9]{4}= | US social security number, e.g. *123-45-6789* |

=%<nop>SEARCH{type="regex"}%= also supports the =;= and =!= operators in regular expression searches.
   * =;= is used to indicate an "and" search. For example, =Peace;War= to search for topics matching the regular expressions =Peace= _and_ =War=.
   * =!= is used to negate the sense of the following regular expression. For example, =Peace;!War= will find topics that match the expression =Peace=, but do _not_ match the expression =War=.
The =";"= and ="!"= operators are =%SEARCH= -specific and are not part of the standard regular expression syntax.

---++ Use of Advanced Regular Expressions

Foswiki strives to support as much as possible of the Perl syntax for regular
expressions. Be warned, though, that Foswiki only guarantees to support a
subset of regular expression syntax, as documented in
Foswiki:Development.RegularExpressions. This limitation is imposed by the
third-party tools that Foswiki integrates with.

You can use more advanced features of Perl regular expressions, but your
searches are not guaranteed to be supported on all Foswiki configurations,
for example where a database store is in use and the database doesn't support
the full Perl syntax for REs.

*Related Links:* 
   * http://perldoc.perl.org/perlretut.html - Regular expressions tutorial
   * http://www.perl.com/doc/manual/html/pod/perlre.html - Perl regular expressions

---
*Related Topics:* UserDocumentationCategory
