I'm starting with RegEx and I need help, I want to validate that there are two equal characters followed by A, or that they are separated (but remain the same) and in the middle A. I explain with examples:
BBA -> true
ABB -> true
BAB -> true
CCA -> true
ABC -> false
BAC -> false
BBBA -> false (there have to be only two)
ABBB -> false (there have to be only two)
At the moment I have something similar to this, but it does not work correctly:
(([B-Z])\1{2}A) | ([B-Z]{1}A[B-Z]{1}) | (A([B-Z])\1{2})
I know I'm not getting close to the correct answer, what I'm learning. If someone could give me a hand I would appreciate it very much.
Use \b to match only words, and back references for each |.
\b([B-Z])\1A|([B-Z])A\2|A([B-Z])\3\b
Check: https://regexr.com/42bp0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With