How to make end of one match is start of other

Viewed 36
1 Answers

Your regex matches the string

AWERTYUIOPAZXCA
|---------| 
A[^A]+    A

This is the only pattern in that string.

The remaining string doesn't match anymore, because it doesn't begin with A:

ZXCA
|
A...

If you change the string to: AWERTYUIOPAAZXCA it will match twice:

AWERTYUIOPAAZXC      A
|---------||---------|
A[^A]+    AA[^A]+    A

If you use a positive lookahead, you can assure to only match strings that end with an A:

((A[^A]+)(?=A))

This will give you AWERTYUIOP and AZXC - you need to tweak the regex if you want to capture the last character but it doesn't capture if the string/character (A) is not present.

Related