Reputation: 9
What is a regex for ignoring words in a given sentence?
Input:
Online Mobile Order is not working
Output:
Online Mobile Order
I'm trying to get some automation tool to flag cases where the combination Online Mobile Order appears.
In my current case I use it as follows: (Online Mobile Order|Mobile Online Order|Online Order Mobile)
This allows to flag these combinations regardless of their ordering.
But, sometimes I need to capture "Online Mobile Order is not working" but the addition of "is not working" will not flag this sentence for me.
I was looking for similar answers here but since I'm not across Regex, I wasn't sure if any answer was matching my problem.
Upvotes: 0
Views: 75
Reputation:
This works if your engine supports conditionals.
By and large its PCRE, Perl, Boost.
(?i:(?m:[ ]|^)(?:(?(1)(?!))(Order)|(?(2)(?!))(Mobile)|(?(3)(?!))(Online))){3}
https://regex101.com/r/w7zfyV/1
Expanded
(?i:
(?m: [ ] | ^ )
(?:
(?(1)(?!))
( Order ) # (1)
| (?(2)(?!))
( Mobile ) # (2)
| (?(3)(?!))
( Online ) # (3)
)
){3}
Upvotes: 1
Reputation: 1415
This should work:
/^.?(Online Mobile Order|Mobile Online Order|Online Order Mobile).?$/gi
The .?
matches zero or more of any character before and after those word combinations. You should also use the i
flag so it matches any character case.
Use this online regex tester to test.
Upvotes: 0