in reply to Re: help with regex
in thread help with regex

So in other words I will need to check to see if $1 gets set otherwise use $2 correct? I was hoping I could set both to $1

Replies are listed 'Best First'.
Re^3: help with regex
by Anonymous Monk on Mar 27, 2009 at 13:16 UTC
    I guess I could do this:
    while(<DATA>) { chomp; if (/string=\"(\d+)\"|static-address\/(.*?)\"/) { my $id = $1 ? $1 : $2; print "ONE: $id\n"; } } __DATA__ static string="123456" containing numbers html value <a href="static-address/foo">text</a>
      The following would be better:
      if (/string=\"(\d+)\"|static-address\/(.*?)\"/) { my $id = defined($1) ? $1 : $2;

      And then there's this:

      if (/string=\"(\d+)\"/ || /static-address\/(.*?)\"/) { my $id = $1;