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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:08:00+00:00 2026-05-29T12:08:00+00:00

Consider the following string $input = string with {LABELS} between brackets {HERE} and {HERE};

  • 0

Consider the following string

$input = "string with {LABELS} between brackets {HERE} and {HERE}";

I want to temporarily remove all labels (= whatever is between curly braces) so that an operation can be performed on the rest of the string:

$string = "string with between brackets and";

For arguments sake, the operation is concatenate every word that starts with ‘b’ with the word ‘yes’.

function operate($string) {
  $words = explode(' ', $string);
  foreach ($words as $word) {
    $output[] = (strpos($word, 0, 1) == 'b') ? "yes$word" : $word;
  }
  return implode(' ', $output);
}

The output of this function would be

"string with yesbetween yesbrackets and"

Now I want to insert the temporarily deleted labels back into place:

"string with {LABELS} yesbetween yesbrackets {HERE} and {HERE}"

My question is: how can I accomplish this? Important: I am not able to alter operate(), so the solution should contain a wrapper function around operate() or something. I have been thinking about this for quite a while now, but am confused as to how to do this. Could you help me out?

Edit: it would be too much to put the actual operate() in this post. It will not really add value (except make the post longer). There is not much difference between the output of operate() here and the real one. I will be able to translate any ideas from here, to the real-world situation 🙂

  • 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-29T12:08:02+00:00Added an answer on May 29, 2026 at 12:08 pm

    The answer to this depends on wether or not you are able to understand operate(), even if you can’t change it.

    If you have absolutely no insight into operate(), your problem is simply unsolvable: To reinsert your labels you need one of

    • Their offset or relative position (You can’t know them, if you don’t know operate())
    • A marker for their place (You can’t have them, if you don’t know how operate() will work on them)

    If you have at least some insight into operate(), this becomes something between solvable and easy:

    • If operate($a . $b)==operate($a) . operate($b), then you just split your original input by the labels, run the non-label parts through operate(), but obviously not the labels, then reassemble
    • If operate() is guaranteed to let a placeholder string, that itself is guaranteed to be not part of the normal input (“\0” and friends come to mind) alone, then you extract your labels in order, replace them by the placeholder, run the result through operate() and later replace the placeholder by your saved labels (in order)

    Edit

    After reading your comments, here are some lines of code

    $input = "string with {LABELS} between brackets {HERE} and {HERE}";
    
    //Extract labels and replace with \0
    $tmp=preg_split('/(\{.*?\})/',$input,-1,PREG_SPLIT_DELIM_CAPTURE);
    $labels=array();
    $txt=array();
    $islabel=false;
    foreach ($tmp as $t) {
      if ($islabel) $labels[]=$t;
      else $txt[]=$t;
      $islabel=!$islabel;
    }
    $txt=implode("\0",$txt);
    
    //Run through operate()
    $txt=operate($txt);
    
    //Reasssemble
    $txt=explode("\0",$txt);
    $result='';
    foreach ($txt as $t)
      $result.=$t.array_shift($labels);
    
    echo $result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following String : 5|12345|value1|value2|value3|value4+5|777|value1|value2|value3|value4?5|777|value1|value2|value3|value4+ Here is how I want to split string,
Consider the following inputs: String[] input = {a9, aa9, a9a9, 99a99a}; What would be
Consider the following code snippet: String input = Print this; System.out.println(input.matches(\\bthis\\b)); Output false What
Consider the following string: ab(cd.xz) e(ab(fg).xz)) ab(hi.xz) I want to match every substring that
consider following scenario input string = WIPR.NS i have to replace this with WIPR2.NS
Consider the following regex: (([^\|])*\|)*([^\|]*) This matches repetitive string patterns of the type (whatever
Consider the following Scala code def NOTImplementedIn[T<: AnyRef](t:T):String = throw new Exception(t.getClass.getName+: Input type
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following code: std::string my_error_string = Some error message; // ... throw std::runtime_error(std::string(Error:
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)

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.