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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:51:17+00:00 2026-06-11T13:51:17+00:00

I’m trying to use a regular expression to find groups of spaces and replace

  • 0

I’m trying to use a regular expression to find groups of spaces and replace them with another character like $

 $teststring="00005e-000003 D21    3       0004ea-287342 D21    3       000883-d94982 D21    3       000f20-4c5241 D21    3       002561-e32140 D21    3       003018-a1a24f D21    3       00e039-0fe0fe D21    3       08000f-1eb958 D21    3       08000f-1ec4de D21    3       082e5f-498900 D21    3";
 $pattern='/([0-9A-F]{6})-([0-9A-F]{6}) ([0-9A-F]+)\s{1,}([0-9]{1,})/i'; 

 if (preg_match_all($pattern,$teststring,$matches, PREG_PATTERN_ORDER)) {   
        $data = $matches[0];
 }

this is working in that based on my pattern, if i do a print_r on $data, it looks like:

 Array ( 
          [0] => 00005e-000003 D21 3 
          [1] => 0004ea-287342 D21 3 
          [2] => 000883-d94982 D21 3 

       }

what I’d like to do is replace all spaces with $
so the output looks like this:

 Array ( 
          [0] => 00005e-000003$D21$3 
          [1] => 0004ea-287342$D21$3 
          [2] => 000883-d94982$D21$3 
  }

Can you tell me how i can accomplish this?

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-11T13:51:19+00:00Added an answer on June 11, 2026 at 1:51 pm

    If all you want to do is replace all groups of spaces with one dollar sign, you can do something like this:

    preg_replace('/\s+/','$', $subject);
    

    Also as an aside:

    • You can use \d instead of [0-9] to match one digit
    • You can use + to match one or more character instead of {1,}
    • Instead of using //i to do a case-insensitive search, I think making your hex character class [0-9a-fA-F] would be a little more efficient… though I didn’t do the leg work.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.