Here is my problem: I have a php file which contain this "html" code:
<div>
{{ '{# Hi :D #}' }} {# Hello #}
{{ $model }}
</div>
In my code I want to get the {# #} and the {{ }} to do different regex replacement but not the one that are in {{ }}.
The problem here is that if I do in the same (in PHP) preg_replace for the two possible match, this doesn't take the {{ }} found (That's what I want) but the replacement will be the same for the two:
/{{(.*?)}}|{#(.*?)#}/
This is logic but I want to do different replacements for each $1 and $2 match.
I thought to those possibilities :
- First is to tell the regex to do not take the strings that are in the "{{ }}" parent but after multiple tentatives I failed to.
- Second possibility is to add another replacement, in the preg_replace function you can do an array() replacement but this doesn't work like $1 = the first replacement and $2 = the second replacement, there is a replacement per regex request.
After 2 days trying to create this magic regex I finally ask a question in stackoverflow, hope someone will found the answer to this regex
Thanks,
preg_match_all, if in index 1 it is{{(.*?)}}, if in index 2 it is{#(.*?)#}.'{# Hi :D #}'in the{{ }}? I want to change the{# Hello #}but not the things in the{{ }}and what if I have multiple{# #}, the indexes doesn't work anymore{# #}and the{{ }}to do different regex replacement but not the one that are in{{ }}" could possibly mean. You wantxandyto do different things but not the ones that are iny. Sometimes you wantyto do something and other times to not do something? That's gonna be a bit tough ;)