Logical OR (Alternation) operation (a|b)


What is a logical OR operation? How to specify a logical OR operation in a regular expression?

How to use logical OR operations to build a regular expression to search and count common spamming terms from this email paragraph: I am inviting you for a business deal where this money will be shared between of us in the ratio of 60/40 percentage. Am assured you that within (7) seven banking working days, this said amount will enter your given Bank account with immediate alacrity. If you agree to my business proposal, further details of the transfer will be forwarded to you as soon as I receive your wiliness to join hand with me."

✍: FYIcenter.com


A logical OR operation, also called alternation, enables us to choose from one of several possible patterns. Character '|' is used as the logical OR operator.

Here are some examples of logical OR operations:

color|colour        # matches "color" or "colour"
Mon|Tue|Wed|Thu|Fri # matches "Mon", "Tue", "Wed", "Thu" or "Fri"

The regular expression to capture some common spamming terms is:

(business deal|bank account|business proposal)

business deal - spamming term
| - logical OR operator
bank account - spamming term
| - logical OR operator
business proposal - spamming term

Click the button to test this regular expression here online:

2013-01-22, 0👍, 0💬