Geo::UK::Postcode::Regex::Simple - Simplified interface to Geo::UK::Postcode::Regex
Localised configuration:
use Geo::UK::Postcode::Regex::Simple ':all'; # Set behaviour of regular expression (defaults below) local $Geo::UK::Postcode::Regex::Simple::MODE = 'strict'; local $Geo::UK::Postcode::Regex::Simple::PARTIAL = 0; local $Geo::UK::Postcode::Regex::Simple::CAPTURES = 1; local $Geo::UK::Postcode::Regex::Simple::ANCHORED = 1; local $Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE = 0; # Regular expression to match postcodes my $re = postcode_re; my ( $area, $district, $sector, $unit ) = "AB10 1AA" =~ $re; # Get hashref of data parsed from postcode my $parsed = parse_pc "AB10 1AA"; # Extract list of postcodes from text string my @extracted = extract_pc $text; # Check if string is a correct postcode if ( validate_pc $string ) { ... }
Alternate global configuration:
use Geo::UK::Postcode::Regex::Simple # ':all' # -strict # or -lax, -valid -full # or -partial -anchored # or -unanchored -captures # or -nocaptures -case-sensitive # or -case-insensitive ;
Alternative interface to Geo::UK::Postcode::Regex.
Please note that various bugfixes have changed the following:
extract_pc, parse_pc now die with invalid import options set
extract_pc
parse_pc
Unanchored regular expressions no longer match valid postcodes within invalid ones.
Unanchored regular expressions in partial mode now can match a valid or strict outcode with an invalid incode.
Please get in touch if you have any questions.
Sets the regular expressions used to be in one of the following modes:
Matches anything that resembles a postcode.
Matches only if postcode contains valid characters in the correct positions.
Matches only if the postcode contains valid characters and the outcode exists.
If true, regular expression returned by postcode_re will match partial postcodes, at district (outcode) or sector level, e.g. "AB10" or "AB10 1".
postcode_re
Puts anchors (^ and $) around the regular expression returned by postcode_re.
^
$
Puts capture groups into the regular expression returned by postcode_re. The matches returned upon a successful match are: area, district, sector and unit (or outcode, sector and unit for 'valid' mode).
If false, only parses/matches/extracts postcodes that contain only upper case characters.
my $re = postcode_re;
Returns a regular expression which will match UK Postcodes. See CONFIGURATION for details.
my $parsed = parse_pc $pc;
Returns a hashref of data extracted from the postcode. See parse in Geo::UK::Postcode::Regex for more details.
parse
my @extracted = extract_pc $test;
Returns a list of postcodes extracted from a text string. See extract in Geo::UK::Postcode::Regex for more details.
extract
if ( validate_pc $pc ) { ... }
Boolean test for if a string is a (full) postcode or not, according to current MODE (see CONFIGURATION).
Michael Jemmeson <mjemmeson@cpan.org>
Copyright 2015- Michael Jemmeson
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Geo::UK::Postcode::Regex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::UK::Postcode::Regex
CPAN shell
perl -MCPAN -e shell install Geo::UK::Postcode::Regex
For more information on module installation, please visit the detailed CPAN module installation guide.