Gary Stainburn wrote: > However I'm having problems with the regex. The criteria is: > > The postcode may or may not have anything before it (the $1 bit) > The postcode may only have whitespace, '.' or ',' after it (which does not > want to be kept) > > The postcode is of the format > 1 or 2 letters > 1 or 2 numbers, > optional space > 1 number > 2 letters >
That can be translated 1:1 to Perl: my $postcode_re = qr/[A-Za-z]{1,2} # 1 or 2 letters \d{1,2} # 1 or 2 numbers \s? # optional space \d # 1 number [A-Za-z]{2} # 2 letters /x; So now we can build the regexp for your problem: if ($lastline =~ /(.*)($postcode_re)[\s.,]/) { my $stuff_before_code = $1; my $postcode = $2; ... } > If it is only a partial postcode it will have only up to the optional space. > However, if this cannot be catered for, it's not the end of the world. I can't answer it, as I don't know what a partial postcode should be (I'm not from the UK). Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]