LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2011, 01:11 AM   #1
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Rep: Reputation: 30
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...
 
Old 10-25-2011, 01:38 AM   #2
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Original Poster
Rep: Reputation: 30
Ah, solved it myself:

hello(?! world)

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex to match C-1234567-01-A3 Daravon Programming 5 07-23-2010 10:07 AM
What should some Regex match in awk? sebelk Programming 7 11-20-2009 06:38 PM
Help with regex to match an IP abefroman Linux - Server 5 11-02-2009 03:07 PM
Extract everything before a regex match onesikgypo Programming 5 10-21-2009 04:49 AM
help me match this regex line (easy) JustinHoMi Programming 7 03-17-2002 01:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration