in reply to optional regexp parts?

For example:.......... (\d{1,4})\t(.{1,40}) ............I only want to look at $1 and $2 if the \t is present. If the \t isn't present, I wish to just deal with $1.

Replies are listed 'Best First'.
Re: Re: regexp
by diotalevi (Canon) on Jun 13, 2003 at 13:37 UTC

    Ah, that would be when you check to see whether $2 is defined or not. You get $2 just because it is written into the source of the expression, not because it matched. Its value will be the value undef if the expression matches and that portion of the expression was not used. So for the expression /(\d{1,4}) (?:\t (.{1,40}) )?/x the tab with following stuff is optional and then you just look at the parts that interest you.