Regex4 - Subexpressions

07th May, 2009 | regex

Alternatives are defined with the binary OR metacharacter, the pipe |

This will find either bob or sam:

egrep 'bob|sam' text.txt

Subexpressions can be defined with parenthesis metacharacters to limit scope

This will find submarine and subclipse:

egrep 'sub(marine|clipse)' test.txt