scferg5
scferg5

Reputation: 2013

Regex match list of strings that can contain spaces

I'm using a regex expression to match from a list of strings:

/(Art|Dance|Writing|Theater \(Musical\))/g

The problem I'm running into is that single-word strings "Art", "Dance", "Writing", etc. match perfectly, but I can't figure out how to match "Theater (Musical)". Everything tip I've found is for matching any string that can contain spaces, but I need it to only be from the given list.

I believe the software we're using uses the javascript regex flavor, if that makes any difference.

Upvotes: 0

Views: 2373

Answers (1)

user1919238
user1919238

Reputation:

The regex in your question is correct and will match the input Theater (Musical).

Here it is in Regex 101.

It also will correctly match even if you have the i case insensitive flag set. (Of course, it will also match THEATER (mUsIcAl) etc. in that case).

There must have been some other issue with your code or input data.

Upvotes: 4

Related Questions