in reply to Re: Re: Re: Re: Capturing everything after an optional character in a regex?
in thread Capturing everything after an optional character in a regex?

Regular expression readability notwithstanding, I'm missing the point I guess.

I think readability was exactly his point. Use /x and comment where each capture starts. I see both of your points though I do think that hardburn went off on a bit of a tangent by bringing up /x in the first place. Using the modifier certainly doesn't make it any easier to deal with the two sets of parens in your code, just in your mind.

The easiest solution I see to the counting problem is just to wrap the entire expression in an outter set of parens so that $1 captures both the right or the left side of the alternation.

But you can't do that because then you'd be capturing the 'X' in the first alternative which is just what you want to avoid.

But the point is moot I guess, since sauoq's answer seems to have solved the OP's problem in a more graceful way anyway.

Or not. The problem being that he never really did tell us exactly what he wanted. Sigh and shrug.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Re: Re: Re: Re: Capturing everything after an optional character in a regex?