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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -