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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:14:25+00:00 2026-05-31T23:14:25+00:00

Can anyone please help me with this…I’m not very good with regular expressions and

  • 0

Can anyone please help me with this…I’m not very good with regular expressions and I’m banging my head since days!

In Smarty I have this array o values included in curly brackets captured in variable $str:

{capture assign=str}{literal}
{label1: \"value1\",label2: \"value2\", label3: \"value3\",label4: \"value4\"},
{label1: \"value1b\",label2: \"value2b\", label3: \"value3b\",label4: \"value4b\"},
...
{/literal}{/capture}

I need to overwrite a series of labels and values (from { to } ) if label1: \”value1\” match my string.

This is what I got so far…

{capture assign=foo_regex}{literal}/[{label1:\s*\\"{/literal}{$smarty.get.value1}{literal}\\",\s*label2:\s*\\"{/literal}{$smarty.get.value2}{literal}\\"].*[}]/g{/literal}{/capture}
{capture assign=foo_replace}{literal}{-my new string-}{/literal}{/capture}
{$str|regex_replace:$foo_regex:$foo_replace}

any wizard out there please help ?
Thank you in advance !

Update:
I came out with the correct expression, but it’s not working with Smarty regex…what am I doing wrong?
http://regexr.com?30dnp

Update2 @ lorenzo: when label1: \"value1\",label2: \"value2\" matches my string I overwrite it with a new string from { to } like this {label1: \"value1\",label2: \"value2\",label3: \"value3\",label4: \"value4\"}

What it does: check if stored value1 and value2 match my test string, if positive -> update all other values (4,5,6) with my new string values.

Hope now it’s clearer what I want to achieve.

  • 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-31T23:14:26+00:00Added an answer on May 31, 2026 at 11:14 pm

    Solution (for others who may need a hint on the subject):

    1. got the correct php formatting for my expression with this useful online tool: http://www.techeden.com/regex

    2. then created a php snippet (udt) in my CMSMS admin to replace from { to } when match is found:

      $result = preg_replace('/.*(?:label1\: \\\\\"'.$params['value1'].'\\\\\").*(?:label2\: \\\\\"'.$params['value2'].'\\\\\").*[}]/m', $params['replace'], $params['str']);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me spot the problem on this PLEASE? I'm eternally grateful for
Can anyone please help me with this? I have a Windows 2008 server and
can anyone please help me with this query. I have a CSV file which
Can anyone please help me with this? I've got a .jar file for which
Can anyone please help me with this ? I am moving on using PyDev
Can anyone please help me read this shorthand code? datain = $this.hasClass('up')?+1:($this.hasClass('down')?-1:null); sorry for
Can anyone please help me with this. I am new to css styling. I
Can any one please help me solve this. I am resizing some flash object/embed
Can anyone please help me to know how to open an excel sheet in
Can anyone please help me to work out how to achieve the following? 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.