Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:19:30+00:00 2026-05-27T20:19:30+00:00

I really don’t know enough about regex to tackle this on my own so…

  • 0

I really don’t know enough about regex to tackle this on my own so…

I am playing with geolocation API and my goal is to get a rough idea about the whereabouts of the visitor so I can list services on offer in that particular area.

this is done via the leading part of the postcode string. eg n17 9ht, my interest is in n17

that’s all fair but I get different outputs in chrome and IE9, firefox is miles better and returns a postalCode string automatically.

  • chrome: 2 Castlebar Park, London, Greater London W5 1BX, UK
  • ie9: 3-6 Mt Ave, London Borough of Ealing, London W5, UK

whereas neither of these is my address, W5 is correct.

the question is, how do I extract just W5 out of the two possible strings i am being given?

Obviously, the string is being split by ,, so I am looking at getting W5 (or any possible uk postcode leading part) from a string looking like:

  • Greater London W5 1BX
  • London W5

it will always have a space between the 2 parts of the post code (if 2-nd is supplied).

I don’t care about BFPO / GIR cases so it’s pretty much just part 1, which can be as simple as n1 or ec3a – so the way I figure, the logic needs to be:

  1. extract either the full or partial postcode.
  2. take part 1 (or the only part) and pass it on.

any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:19:30+00:00Added an answer on May 27, 2026 at 8:19 pm

    Here is the one of the longest regular expression which supports all UK postal code syntax according to Wikipedia article (including partials):

    ([A-Z]?\d(:? \d[A-Z]{2})?|[A-Z]\d{2}(:? \d[A-Z]{2})?|[A-Z]{2}\d(:? \d[A-Z]{2})?|[A-Z]{2}\d{2}(:? \d[A-Z]{2})?|[A-Z]\d[A-Z](:? \d[A-Z]{2})?|[A-Z]{2}\d[A-Z](:? \d[A-Z]{2})?),\s*UK$
    

    I didn’t test it properly, but at least works for your cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really don't know squat about java memory management, so this is entirely my
I really don't know much about Apache, I followed some tutorials and installed the
I really don't know how to title this question, but I need some help
I really don't know much about attributes in general in C#, I've seen them
I have this json object (which i don't really know what is inside) and
I have this problem and really don't know how to solve this. I'm having
I really don't know how to express this question. But what I'm trying to
I really don't know how to say, may be this is why I didn't
I really don't know, why this is so complex and hard just for reading
I really don't know how to word this question, so I'll give an example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.