Reputation: 60
I'm a newbie to regular expressions and i have a problem in identifying the same consecutive words using regular expression. below is the scenario.
Here is the data :
;af;aj;am;an;ao;ap12;aq123;ar;as;ad;af1223;
and my current regular expression is (;[a-z][a-z];)
and it only matches the below sets ;af; , ;am; , ;ao; , ;ar; , ;ad; but my expectation is to match all these sets. ;af;aj;am;an;ao; & ;ar;as;ad;.
Could guys please guide me how to match these patterns?
Upvotes: 0
Views: 88
Reputation: 67968
(;[a-z][a-z](?=;))
Try this.This returns the group you are looking for though its not clear how they are same.
The reason why urs was not working wass due to that fact (;[a-z][a-z];
) doesnt leave a ;
for the next element to start with.So it is not able to match as there is no ;
in front of it.A lookahead assertion doesnt cosume ;
thereby enabling all matches.
See demo.
http://regex101.com/r/tF4jD3/4
Upvotes: 0
Reputation: 174706
It seems like your trying to extract the substrings which are in this ;[a-z][a-z];
format. If yes, then you could simply put your regex inside a lookahead to do a overlapping match.
(?=(;[a-z][a-z];))
Upvotes: 2