I hope that someone can help me... I'm not a regex expert and I'm looking for a solution for handle a text substitution.
I have an HTML code like this:
<script>
...something here...
</script>
<script type="text/javascript">
...something here...
</script>
...something here...
<script type="text/javascript">
1st occurrence
...something here...
fbq(...something here...)
...something here...
</script>
...something here...
<script type="text/javascript">
2nd occurrence
...something here...
fbq(...something here...)
</script>
...something here...
I need to find all string between ' that contains the function fbq. So in my example I need to have:
Group1:
<script type="text/javascript">
//1st occurrence
...something here...
fbq(...something here...)
...something here...
</script>
Group2:
<script type="text/javascript">
2nd occurrence
...something here...
fbq(...something here...)
</script>
And so on if there are more occurrences. I think It will be fine also to have more matches instead of more groups.
Consideration: there can be a lot of <script string in my code that doesn't contains 'fbq' function, and I can't be sure how they are positioned and whether in a newline or not.
I've tried many regex code but I cannot find something that works.
I.e. by using
(?:^.*)(<script.*fbq.*<\/script>)(?:.*$)
or
.*(<script.*fbq.*<\/script>).*
I can find only the last occurrence of fbq (in my example only 2nd occurrence).
I've tried also to play with groups inclusion but with no luck.
Then I need to use this regex in a PHP code, for doing a substitution using preg_replace
Any suggestion is very welcome
Thanks in advance!
DOMDocument) instead.