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

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>

Replies are listed 'Best First'.
Re^4: help with regex
by ikegami (Patriarch) on Mar 27, 2009 at 16:29 UTC
    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;