I am using Java. I have the following text:
"hyst and hy"
Why (hy)(?![a-z]) returns two "hy"s. The idea is to match any "hy" that is not followed by any character between a-z.
If I do hy(?![a-z]) (hy without parentheses) it works (finds only the second "hy") but I don't understand why if I use parentheses (hy) in the RegEx it matches the first "hy" in hyst
When you use a capture group you obtain two results, the first is the whole pattern and the second the capture group. The first hy
has never been matched.
If you remove the parenthesis, you obtain only that match the whole pattern.
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