Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda