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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:21+00:00 2026-05-26T20:06:21+00:00

How do you do a regex in php that finds a space that has

  • 0

How do you do a regex in php that finds a space that has a letter on its left and a number on its right?

I have done many of these over the last day and at best I can find the “letter space number” combo, but I do not know how to find just the space between the letter and number. I would like to replace this space with a comma.

E.G:

The big red Fox 283 brown balls

would be converted to:

The big red Fox,283 brown balls

Thank you in advance for answering this question. If you provide an explanation with how the answer works it would be greatly 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-26T20:06:22+00:00Added an answer on May 26, 2026 at 8:06 pm

    You can use the preg_replace function to do this:

    $string = 'The big red Fox 283 brown balls';
    preg_replace('/([a-zA-Z]) ([0-9])/', '$1,$2', $string);
    

    The [a-zA-Z] part of the regex matches any letter, and the [0-9] matches any digit. Together, /[a-zA-Z] [0-9]/ means that we want to match any letter followed by a space, followed by a digit.

    The circle brackets denote backreferences, which allows parts of the original string to be “remembered” (in the variables $1 and $2) so that we can include those matched strings in the replacement string.

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

Sidebar

Related Questions

I have a function that finds a regex thingy, then replaces with php code.
I need a Regex expression for PHP that finds exactly 8 characters in a
I need a PHP Regex that can parse .strings files. In particular, it needs
I am attempting (and failing) to write a PHP regex that will match a
I need a regex or a function in PHP that will validate a string
I have noticed in the PHP regex library there is a choice between ereg
I have borrowed code from this link PHP regex templating - find all occurrences
I need a REGEX that can find blocks of PHP code in a file.
I have a simple text that is being parsed with PHP. In that text,
I have a RegEx that is working for me but I don't know WHY

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.