in reply to Need help with perl regexp

Is the following doing what you wanted ?
use warnings; use strict; while (my $address = <DATA>) { my ($street, $number) = ( $address =~ / \A # start of s +tring ( \w{3} \. \s \w{3} \s \w{3} ) # 'aaa. bbb +ccc' \s # followed b +y a space (?:nr\. \s )? # optional ' +nr. ' \w{3} # 'ddd' (\d+) # 'ddd...' /ix ); print "Street: $street, Number: $number\n"; } exit; __DATA__ aaa. bbb ccc nr. ddd23-56


Krambambuli
---
Enjoying Mark Jason Dominus' (aka Dominus) "Higher-Order Perl"

Replies are listed 'Best First'.
Re^2: Need help with perl regexp
by flaviusm (Acolyte) on Oct 22, 2007 at 19:03 UTC

    Thank you Krambambuli. I don't understand completly the regexp you submitted, but it seems that the version submitted by "mwah" is more generic.

    I forgot to mention in the statement of the problem that the "aaa" is in fact "aaa+", a given token can contain any number of characters not just those I used in my example

    I appreciate the help of you all.