LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Regex: Match 'Hello' but not 'Hello world' (https://www.linuxquestions.org/questions/programming-9/regex-match-hello-but-not-hello-world-909968/)

davee 10-25-2011 01:11 AM

Regex: Match 'Hello' but not 'Hello world'
 
Hi all,

Is it possible to 'look ahead' with regex?

For example, say I want to match 'hello':

e.g.
>I want to say hello to you - match

but not when it was followed by a specific word, say 'world':

e.g.
>hello, good morning - match
>My output is hello world - don't match
>hello and goodbye - match

My hazy recollection is that this is not possible to look ahead with a single line of regex - do I remember correctly?

Thanks in advance...

davee 10-25-2011 01:38 AM

Ah, solved it myself:

hello(?! world)

New regex (for me) in Perl 5...


All times are GMT -5. The time now is 06:56 AM.