0

I would like to use regex to match following strings:

aba
ababaa
abababaaa
...

These strings follows the pattern :

(ab){1}(a){1}
(ab){2}(a}{2}
(ab){3}(a){3}
...

Is it possible to create a generic regex to much such pattern ( like (ab){n}(a){n} ) ?

anubhava
  • 761,203
  • 64
  • 569
  • 643
Pafcio
  • 71
  • 1
  • 1
  • 4

2 Answers2

0

Try using quantifiers

(ab)+(a)+

+ means 1 or more and * means 0 or more

rhymefororange
  • 341
  • 1
  • 7
0

The answer was posted by Wiktor Stribiżew. Using PCRE syntax regex the solution is recursive pattern:

(ab(?1)?a)
Pafcio
  • 71
  • 1
  • 1
  • 4