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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -