Wednesday, January 28, 2009

Alternation

Sometimes you do not need exact matches, or you need to decide between several options. You can define two or more options for the regexp-engine to match. This works like an logical or .

(vehicle|car|van|truck)

I love my car!
I like my van!
My vehicle likes me!
Do trucks like cars ?

This group matches anything with vehicle or car or van or truck.

If you put an s behind the group, only the plural will match.

(vehicle|car|van|truck)s

Do trucks like cars ?

No comments:

Post a Comment