scott lafoy
scott lafoy

Reputation: 1013

Regular expression for matching like given words

I am trying to put together a regular expression for matching multiple words. I have an import file the has a column header that will be something like "item description" since there will be multiple headers it can't get too greedy on what matches. For example "item location description" should not match when looking for "item description" it will have its own matching regex.

I have put together the following: (?i)(?<=^|\s)Item Description(?=\s|$) but it does not quite work for all cases.

Some Valid Cases (ignore case):

Some Not Valid Cases (ignore case):

Upvotes: 0

Views: 58

Answers (2)

Arnaud F.
Arnaud F.

Reputation: 8462

You can easily test your Regex on RegexStorm website.

For your purpose, if the only case that doesn't fit is the one with "_", just add it to your pattern :

(?i)(?<=^|\s)Item[ \t_]Description(?=\s|$)

Upvotes: 0

Thomas Ayoub
Thomas Ayoub

Reputation: 29471

You can use:

(?i)item[ _]description

Upvotes: 1

Related Questions