I am trying to check a webpage for the existence of a google analytics script tag. This seem like it should be easy but my regex skills seem to be lacking. So as a simple example I was trying to match the open and close script tags which have the "google-analytics" between them.
So for example if you have:
<script scr="whatever"></script>
<script>other script</script>
blah blah blah
<script>
blah blah google-analytics
<script>
Then the regex:
/<script>([s/S/]*?google-analtics[s/S/]*?)<\/script>/
This will return a string starting at the first script tag and include the other script tags. So something like:
other script</script> blah blah blah <script> blah blah google-analytics
But of course I only want the string
blah blah google-analytics
So the next step is to include a negative look ahead like:
/<script>((?![s/S/]*?script)[s/S/]*?google-analytics[s/S/]*?)<\/script>/
But that doesn't seem to work. I tried a bunch of different combination of capture groups and the '[s/S/]*?' in front and behind.
Basically I am trying to match a string as long as it doesn't include a substring. Which sounds like a common problem but for the life of me I can't get to work. I have google a ton and all of the example are straightforward but don't seem to work. I have been testing using https://regex101.com/r/hN5dK5/2
Any insight would be helpful. (script is running as php)