Regex optional capturing group?

The reason that you do not get an optional cat after a reluctantly-qualified .+? is that it is both optional and non-anchored: the engine is not forced to make that match, because it can legally treat the cat as the “tail” of the .+? sequence. If you anchor the cat at the end of the … Read more

Regex optional group

You can easily simplify your regex to be this: I’m not sure whether the input string without the first group will have the underscore or not, but you can use the above regex if it’s the whole string. regex101 demo As you can see, the matched group 1 in the second match is empty and … Read more

tech