Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Small Template-system, end of /if does not detect correct

If i write the next line alone he cut's it for no reason, so...:

Hello,

i need help for this, i'm out of my knowledge.

i'm stuck at a small TPL-System which should do some foreach and if statements. I do this in PHP but idk if this relevant.

https://regexr.com/62ho9 here you can see my issue. I want that the regex end by the second {/if} but it does not. Is there any possible solution to do this with regex?

If not, do you maybe have a good idea for PHP to do what i want? Because i'm out off ideas.

(?<={if \!TEST})([\s\S]*?)(?={\/if})
    <a class="dropdown-item" href="#">
        {if !TEST}
          {USERNAME}
          {if !TEST}
            HI
          {/if} 
          klöaksdölsa
        {/if}

        asdas

        {if !TEST}asd{/if}
    </a>

At the moment i use {if ID statement} LOREM {/if ID} but the more elegant solution would be without an ID :D

(TEST: Hi guys) <-- because he cuts it every time from the start?!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, you can use recursion in PHP regex and the regex you could use is

(?s){if\s+!TEST}((?:(?!{(?:if\s+!TEST|\/if)}).|(?R))*){\/if}

See the regex demo. You just need to get the Group 1 value after you get a match.

Details:

  • (?s) - an s inline flag
  • {if\s+!TEST} - {if, one or more whitespaces, !TEST}
  • ((?:(?!{(?:if\s+!TEST|\/if)}).|(?R))*) - Group 1: zero or more occurrences of
    • (?!{(?:if\s+!TEST|\/if)}). - any char that is not the starting point of a {if !TEST} and {/if} char sequences
    • |
    • (?R) - the whole pattern recursed
  • {\/if} - an {/if} substring.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!