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