[Previous] [Contents] [Next]


Grouping and Choice


Regular expressions also enable us to group characters or character classes together, via parentheses: ( and ). Using these in combination with other operators enables us to form even more powerful regular expressions, such as "(very){1,}", which would find a match in all of very good, very very good, and very very very very very smokin' good.

Combined with the | metacharacter, which matches any of the sequences it separates, we can create groups to match individual words: (good|awesome|amazing|sweeet|cool). Note that groups are a more complicated construction, however, and as such tend to be a bit slower in execution. Therefore, although we could write the character class [aeiou] as (a|e|i|o|u), we probably do not want to.


[Previous] [Contents] [Next]