What regex matches strings of consecutive 'a' and 'b'? -
i need regex matches strings of consecutive a , b, e.g.:
ababa bab edge case (smallest):
ab ba (no upper limit.)
...and shouldn't match:
abba bbab bbaabb i've tried several regex 1 kind of tricky. can throw me hints?
my tries:
(a|b)+(ab|ba)*(aba|bab)+
this 1 gets close! http://www.regexr.com/38lqg
if want find matches within text (potentially several words per line):
\b(((ab)+a?)|((ba)+b?))\b \b word boundary.
Comments
Post a Comment