in reply to Need help with perl regexp

The (.*?) at the beginning of your regex is matching minimally, as requested. The problem is that you end up with a zero-length match. I'd use ^(.*?)\s+ instead, which will not only grab the street name like you intended, it will also truncate trailing spaces from it.

The rest of your regex could use some love too, but this should get you started.

I'd write:

my ($street, $number) = $address=~/ ^(.+?) # capture street name \s+ # ignore following whitespace (?:nr\.\s*){0,1} # ignore optional "nr." and trailing w +hitespace \w+? # ignore alphanumerics which come befo +re... (\d+) # capture digits followed by... -\d+ \s* $ # ignore a hyphen, extra digits and en +d of line /x;
(edited example to be more robust on street names like "33-44th St")

Replies are listed 'Best First'.
Re^2: Need help with perl regexp
by ikegami (Patriarch) on Oct 22, 2007 at 18:37 UTC

    That doesn't help.

    ^ (.*?) "aaa." \s+ " " (nr\.)* "" \b\D* "bbb ccc nr. ddd" (\d+) "23" [\d\w-]+\b$ "-56"
      That's not my regex that you just quoted.