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 7006799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:31:27+00:00 2026-05-27T21:31:27+00:00

I need to match using regular expression in php addresses like: 144 street, city,

  • 0

I need to match using regular expression in php addresses like:

  • 144 street, city, state zip/postal code
  • 144 street, apt #1, city, state zip/postal code
  • 144 street apt #1, city state zip/postal code

The zip/postal code can includes letters and/or numbers.

Here’s what I tried:

print_r(preg_match('/^([0-9]+)\s([a-z]+)\s([a-z]+)\s([a-z]+)\s([a-z0-9]+)$/i', $t, $m));
print_r($m);

it outputs:

Array
(
    [0] => 123 asd asd asd 123
    [1] => 123
    [2] => street
    [3] => city
    [4] => state 
    [5] => zip
)

This works using spaces only. When I have a comma it does not work and it result in an empty array.

What can I do to also includes commas?

  • 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-27T21:31:28+00:00Added an answer on May 27, 2026 at 9:31 pm

    Why not simply remove the comma and then use your regular expression?

    Also for alphanumeric zip you might need to add other characters than a-z0-9 since Canadian zip codes use space.

    The other thing you will need to check is if a street has spaces in it like:

    1000 NW One Way Drive

    OR

    100 Rue Des Peupliers

    Your regular expression will not work. Same for City.

    Using an API is good but you have to get the API for the countries you need. If you want to validate All of the country that can be painful.

    ceejayoz has a good answer, but what I think you should do is get the API for the top countries you get and then use the regex for everything else.

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

Sidebar

Related Questions

I need to match and remove all tags using a regular expression in Perl.
I'm using python regular expression module, re . I need to match anything inside
I need to match the following line using regular expression. Single lines contain the
I have a string like this ch:keyword ch:test ch:some_text I need a regular expression
In PHP if we need to match a something like, [one,two,three] , we could
I need a PCRE(Perl Compatible Regular Expression) that will match all non -images(jpg,png,tiff) from
I need to extract the digits from the following string using regular expression: pc
I need a regular expression that will match any string containing at most 2
I need to match an md5 checksum in a regular expression in a Ruby
I'm working on a program where I need to match a regular expression and

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.