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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:39:34+00:00 2026-06-11T06:39:34+00:00

i am having troubles getting my preg_replace to work for a certain string. This

  • 0

i am having troubles getting my preg_replace to work for a certain string. This is an example of how my original stream looks like:

“This is just a {simple | huge | fast} test to validate {my | your | their} regex”

What i want to do is: I want to replace the parts in between the “{ }” with one (the first one) of the words standing in between. For example:

“This is just a simple test to validate my regex”

So basically what i am currently doing is:

foreach ($zeilen as $key => $value) {

    preg_match_all('/\{(.*?)\}/', $value[15], $arr1);

    foreach($arr1[1] as $key2 => $arrValue){
        preg_match_all('/(.*?)\|/', $arrValue, $arr2);
    }

    preg_replace('/\{(.*?)\}/', 'test', $value[15]);

    echo '<tr>';
    echo '<td>'. $value[15] . '</td>';
    echo '</tr>';

    }

I am using a foreach loop there because there a different lines with the exact same pattern i want to get replaced. I am pretty sure there is a better way to do this, maybe someone can even suggest one to me. My problem here is, that preg_replace is not working at all. The $value[15] is getting echoed out exactly as it was before with the words between { }. No “test” is being displayed. I am not very good at regex!

Thanks a lot to anyone helping!

  • 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-11T06:39:36+00:00Added an answer on June 11, 2026 at 6:39 am

    You are not storing the replaced values anywhere. Also, if you use replace outside the loop, it might affect all occurances of the pattern. I think this will help:

    foreach ($zeilen as $key => $value) {
    
    preg_match_all('/\{(.*?)\}/', $value[15], $arr1);
    
    foreach($arr1[1] as $key2 => $arrValue){
        preg_match('/(.*?)\|/', $arrValue, $arr2);
        $value[15]=str_replace($arr1[0][$key2], $arr2[1], $value[15]);
    }
    
    echo '<tr>';
    echo '<td>'. $value[15] . '</td>';
    echo '</tr>';
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having troubles getting this to work. Basically I have a python program that
I am having troubles getting Selectivizr to work even with a very simple page.
So i've been having some troubles getting this effect to work. Here is an
I'm just getting started with LINQ, and I'm having some troubles. Say I wanted
I'm having some troubles getting regex to replace all occurances of a string within
I have been having troubles getting my makefiles to work the way I want.
I'm having troubles getting this right... I have a Core project with a common
I'm having troubles getting a regex to work. I'm trying to parse a large,
I'm having troubles in getting a grid to work: I want to let users
I am having some troubles getting some regex to work to remove some text,

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.