Reputation: 1013
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):
item description
item_description
some junk before the words item description
item description some junk after the words
Some Not Valid Cases (ignore case):
Item Location Description
Location Description
media item
type description
item
Description
Upvotes: 0
Views: 58
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