0

I was just wondering how to match a group which has characters already in another group.

If we take this string for example: "aba" and want to match every group of (ab) or (ba).

Obviously (ab|ba) would work, my only problem with that is it only catches one group which is aba but i also want to capture aba, do I have to use a more complex regex for this case?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
iSupport
  • 53
  • 1
  • 5

1 Answers1

0

You can easily achieve this using this regex

(?=(ab|ba))

It will match all the occurrences of both 'ba' and 'ab' even the overlap ones.

Omar Muhtaseb
  • 117
  • 1
  • 3