in reply to Re: Zipcode Regex Help
in thread Zipcode Regex Help

I have something similiar to your code that is working now. I'm just curious, why the regex I was using isn't working the way the I expected.

Replies are listed 'Best First'.
Re: Zipcode Regex Help
by Abigail-II (Bishop) on Jun 26, 2003 at 01:39 UTC
    Because that's not how the return value of matches is defined. In scalar context, a succesful match returns the number of times it matched. Without the /g, this will always be 1. With /g, this might be more, but that wouldn't help in your case. An unsuccesful match in scalar context returns the empty string, regardless of any flags.

    That's the way how it works, and if you want to have different values depending what matched, you need to do a little more work.

    Abigail