Search code examples
regexspam-prevention

Regex to match one of any terms, some terms with spaces


I'm trying to write a RegEx that matches one of several terms, as part of a spam filter. The problem is, some of these terms contain spaces, and I'm having trouble writing a valid expression.

What I originally had (before multiple word temrs) was this:

(?i)(alzheimers|baldness|obese)

Now, I want to add, for example "blood pressure", but the following expression is chucking a barny:

(?i)(alzheimers|baldness|blood pressure|obese)

Solution

  • You can have whitespace characters in an either-or group, your expression works. Check it out for yourself: https://regex101.com/r/56tz6B/1