I need to match following statements:
Hi there John
Hi there John Doe (jdo)
Without matching these:
Hi there John Doe is here
Hi there John is here
So I figured that this regexp would work:
^Hi there (.*)(?! is here)$
But it does not - and I am not sure why - I believe this may be caused by the capturing group (.*) so i thought that maybe making * operator lazy would solve the problem... but no. This regexp doesn't work too:
^Hi there (.*?)(?! is here)$
Can anyone point me in the solutions direction?
Solution
To retrieve sentence without is here
at the end (like Hi there John Doe (the second)
) you should use (author @Thorbear):
^Hi there (.*$)(?<! is here)
And for sentence that contains some data in the middle (like Hi there John Doe (the second) is here
, John Doe (the second) being the desired data)simple grouping would suffice:
^Hi there (.*?) is here$
.
╔══════════════════════════════════════════╗
║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
║▒▒▒Everyone, thank you for your replies▒▒▒║
║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
╚══════════════════════════════════════════╝
^Hi there (.*)(?<! is here)$
or what @Ceremony has written^Hi there ((?! is here).)*$
but for my usage first version is more appropriate Second thing I want to do is find sentences that have structure like this <pre>Hi there James is here</pre> and solution to that is simply^Hi there (.*) is here$
Thank you all for replying! – Collen