Reputation: 1855
Looking for a regular expression to find the words: David and 07888998 per line, They can be found more than once.
This is the data:
abcasdahadMichaeljkhdkjh 0888881SNADNA
SSMA,DAAASDDDavidjhsjdha007888998
asdsdASDDDavidjhsjdha==007888998asffafa
asdsdASDDDavidjhsjdha==007888995asffafa
SSMA|DAAASDDDaidjhsjdha007888998
The regular expression should find 2 matches. Line 2 and Line 3.
Any help is appreciated. Thanks
Upvotes: 1
Views: 114
Reputation:
More ways:
^(?=.*David)(?=.*07888998)
or
(?:.*(?!\1)(David|07888998)){2}
or
(.*(?!\2)(David|07888998)){2}
Upvotes: 0
Reputation: 455152
Since the order does not matter, you can use positive lookahead assertion (assuming the language/tool you are using supports it) as:
^(?=.*David)(?=.*07888998).*$
Upvotes: 3
Reputation: 56390
If order matters, then /David.*07888998/
will find the matches you want.
If it doesn't matter and you want to make sure they both appear at least once, you can just "or" together two regexes that account for either order: /(David.*07888998|07888998.*David)/
Upvotes: 0