What does it matches h(?<=a)b

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

What does it matches h(?<=a)b

Post by nwp »

According to my knowledge the regex

Code: Select all

h(?<=a)b
should match the text 'hab'
as
It matches teh character 'h' naturally.
then it starts looking behind to find an character 'a'
If it finds the character 'a' then it goes forward and matches the next character that should be 'b'[/syntax]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yes, it will match hab. If the "h" wasn't there it would just match "b".
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

This regex will never ever match anything. When it matches the 'h' it looks back from that position in the hope to find an 'a'. Of course, it will always find that same 'h' and therefore fail.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Indeed you're right :oops:
Post Reply