in reply to Need help with perl regexp

There is more than one possible solution depending on the "real" data structure.

Something has been said on your regex by others, so I'll add another version (only)...

... my $address = ... ; my ($street, $n, $number) = $address =~ /(.+?) # first g +roup (nr\.\s+ | \s+) # number +prefix? [A-z]+ # letters + preceeding number (\d+)- # number /ix; print "STREET: $street, N: $n, NUMBER: $number\n" ...

BTW, is this "$n" really needed?

Regards

mwa

Replies are listed 'Best First'.
Re^2: Need help with perl regexp
by flaviusm (Acolyte) on Oct 22, 2007 at 18:51 UTC
    Thanks a lot. It works great. 
    
    The $n is not needed, but I didn't know how to handle the parameters if  "nr." is present or absent.
      The $n is not needed ...

      then the whole expression may be written more compact:

      ... my ($street, $number) = $address =~ /(.+?) # first grou +p (?:\s+ nr \.)? # any number + prefix? \s+ [A-z]+ (\d+) # number fol +lows alpha /xi; print "STREET: $street, NUMBER: $number\n"; ...

      (although it might backtrack more now ;-)

      Regards

      mwa