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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:13:35+00:00 2026-06-04T00:13:35+00:00

I have a simple pattern that I am trying to do a find and

  • 0

I have a simple pattern that I am trying to do a find and replace on. It needs to replace all dashes with periods when they are surrounded by numbers.

Replace the period in these:

3-54
32-11
111-4523mhz

Like So:

3.54
32.11
111.4523mhz

However, I do not want to replace the dash inside anything like these:

Example-One
A-Test

I have tried using the following:

preg_replace('/[0-9](-)[0-9]/', '.', $string);

However, this will replace the entire match instead of just the middle. How do you only replace a portion of the match?

  • 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-04T00:13:36+00:00Added an answer on June 4, 2026 at 12:13 am
    preg_replace('/([0-9])-([0-9])/', '$1.$2', $string);
    

    Should do the trick 🙂

    Edit: some more explanation:

    By using ( and ) in a regular expression, you create a group. That group can be used in the replacement. $1 get replaced with the first matched group, $2 gets replaced with the second matched group and so on.

    That means that if you would (just for example) change '$1.$2' to '$2.$1', the operation would swap the two numbers.
    That isn’t useful behavior in your case, but perhaps it helps you understand the principle better.

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

Sidebar

Related Questions

All I am trying to find out the correct definition of the repository pattern.
I have a string that represents an html document. I'm trying to replace text
I need some help about RegExp in AS3. I have a simple pattern :
I have a simple bean with enum field public class TestBean{ @Pattern(regexp = A|B)
I am using a simple repository pattern and have objects with a LazyList such
I have simple html code that plays YouTube video after click on the image:
i have simple form that uploads image to server and returns php string containing
I am trying to implement the event aggregator pattern in a simple way to
I have this abstract factory pattern that I use in as3 that I am
I am trying to implement a simple Observer pattern using .net Observable class. I

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.