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

  • Home
  • SEARCH
  • 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 8718651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:35:54+00:00 2026-06-13T06:35:54+00:00

Probably really simple for you Regex masters :) I’m a noob at regex, just

  • 0

Probably really simple for you Regex masters 🙂 I’m a noob at regex, just having picked up some PHP, but wanting to learn (once this project is complete, I’ll knuckle down and crack regular expressions).
I’d like to understand how to compose a regex that may contain some data, but must contain other.

My example being, the match MAY begin with numbers but doesn’t have to, however if it does, I need the number and the following 2 words. If it doesn’t begin with a number, just the first 2 words. The data will be at the beginning of the string.

The following would match:

  • 123 Fore Street, Fiveways (123 Fore Street returned(no comma))
  • Our House Village (Our House returned)
  • 7 Eightnine (7 Eightnine returned)

Thanks

  • 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-06-13T06:35:54+00:00Added an answer on June 13, 2026 at 6:35 am

    Something like this should work:

    ^((?:\d+\s)?\w+(?:\s\w+)?)

    You can test it out somewhere like http://rubular.com/ before coding it, it’s usually easier.

    What it means:

    ^ -> beginning of the line

    (?:\d+\s)? -> a non capturing group, (marked by ?:), consisting of several digits and a space, since we follow it by ?, it’s optional.

    \w+(?:\s\w+)? -> several alphanumeric characters (look up what \w means), followed by, optionally, a space and another “word”, again in a non capturing group.

    The whole thing is encapsulated in a capturing group, so group 1 will contain your match.

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

Sidebar

Related Questions

Probably something really simple, but I'm having some real trouble with it. I have
This is probably something really simple but for some reason I just can't seem
Ok, this is probably really simple, but I just can't figure it out. I
There is probably a really simple answer to this but I just can't see
It's probably something really simple, but I'm just learning. There's a page with 3
Probably really simple but I just cannot work out how to use any API's
This is probably a really simple question, but I just can't find any info
So this is probably really simple but for some reason I can't figure it
I know this probably really simple but Im not sure what im doing wrong...
This is probably something really simple, however I am quite new to PHP, 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.