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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:55:07+00:00 2026-06-16T16:55:07+00:00

Hi I’m having some problems with php recurring regexp. I have strings like {{if(x=y)?

  • 0

Hi I’m having some problems with php recurring regexp. I have strings like
{{if(x=y)? {{ true do something || false do something else }}
in my html files. It will be some kind of basic template engine. If I use

$matches=array();
$content = "{{if(x=y)? true do something || false do something else }}";
preg_match_all('/\{\{if\((.*?)\)\?(.*?)\|\|(.*?)\}\}/is',$content,$matches);

returns the results as I expected.

Array(
 [0] => Array
    (
        [0] => {{if(x=y)?
            true do something 
               ||
            false do something else 
               }}
    )
 [1] => Array
    (
        [0] => x=y
    )
 [2] => Array
    (
        [0] => true do something 
    )
 [3] => Array
    (
        [0] => false do something else 
    )
)

But if the pattern is nested with another one like;

{{if(x=y)?
  {{if(y=z)?
     true do something 
   || 
     false do something else 
  }}
||
  {{if(x=a)?
    true do something 
  || 
   false do something else 
  }}
}} 

it takes the first “}}” chars as end of pattern and fails

Array
(
    [0] => Array
    (
        [0] => {{if(x=y)?
            {{if(y=z)?
          true do something 
            ||
          false do something else 
            }}
        )
    [1] => Array
    (
        [0] => x=y
    )
    [2] => Array
    (
        [0] => {{if(y=z)?
    true do something   
    )
    [3] => Array
    (
        [0] => 
    false do something else     
    )
)

I would like to make a recurring regexp so in each part of true or false it should check if the matched content has same pattern again. The logical part of If is already done. I just need a regexp will match the parts so I can loop thru the results.With my Regexp knowledge this is all I could do so far.EDIT
to be more descriptive I need a regexp can parse something like this.

{{if()?{{if()?{{if()?...||...}}||{{if()?...||...}}}}||{{if()?{{if()?...||...}}||{{if()?...||...}}}}}}

but the regexp I used can only catches from first {{if to first }} it finds which returns

{{if(){{if(){{if()...||...}}

which is correct for the regexp. But how can I rule the regexp as “get whole text, find the block between {{if()? and }} till the end and ignore any others if it is not at the end” or “get the most outer {{if()?||}} block.
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-16T16:55:09+00:00Added an answer on June 16, 2026 at 4:55 pm

    I solved the problem with using link. Author of the script made it simple enough with a different style. In my sample I was trying to match the code blocks with regexp and replace them with the data, but he actually replaced the code blocks into php codes and recreates the files in a different folder with same structure and each time page requested, first checks the file existence and updated time and runs the script. pretty smart. Maybe not a perfect solution and rational but solves my problem. thanks anyway

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I would like to count the length of a string with PHP. The string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.