London is a good starting point but if you are aware of regular expressions or regex for UK counties such as Surrey it would be hugely appreciated. Basically I'm creating a web crawler but the information I'm retrieving only gives a London street name, borough and postcode. It does not say London.
Here is a site that gives the London postcodes @droogal
Is there a library of regular expressions that covers London postcodes. If you need to write it, the first part of the postcode gives away the location i.e. London.
There is:
WC, EC, E1-E20, N1-N22, NW1-NW11, SE1-SE28, SW1-SW20, W1-14 and Greater London ... BR, CR, DA,EN, HA, IG, KT, RM, SM, TW, UB, WD.
The language I'm using is Java but saying that regular expressions are found in most languages!
This is what I got so far. How do I do number ranges in regex?
public static void main(String[] args) throws IOException {
String postcode = "WD";
Pattern regex = Pattern.compile("^(WC|EC|BR|CR|DA|EN|HA|IG|KT|RM|SM|TW|UB|WD)");
Matcher finder = regex.matcher(postcode);
if (finder.find()) {
try {
String value = finder.group(0);
System.out.println("This is London");
} catch (NumberFormatException e) {
System.out.println(e.getMessage());
}
}
}
Assuming you have a post code, this matches a London one:
The small thing to note is that the regex passed to
String.matches()
must match the whole string to return true.