I want to get all the script that are loaded in my screen
<script type="text/javascript" src="http://url/pub/static/frontend/Magento/luma/en_US/requirejs/require.js"></script>
<script type="text/javascript" src="http://url/pub/static/frontend/Magento/luma/en_US/mage/requirejs/mixins.js"></script>
<script type="text/javascript" src="http://url/pub/static/frontend/Magento/luma/en_US/requirejs-config.js"></script>
<script type="text/javascript" src="http://url/pub/static/frontend/Magento/luma/en_US/mage/polyfill.js"></script>
<script type="text/x-magento-init">
{"*":{}}
<script>
<script>
var BASE_URL = 'http://urlm/index.php/';
var require = {
"baseUrl": "http://url/pub/static/frontend/Magento/luma/en_US"
};
</script>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-KK5JZ25');</script>
the code i am using is
$conditionalJsPattern = '@(?:<script type="text/javascript"|<script)(.*)</script>@msU';
i want to exclude the googletabmanger code
googletabmanger code contains some words like googletagmanager , gtm
how can i do that???
thanks in advance
2
Answers
Maybe, this expression might be close to what you have in mind:
and you can flag it however you wish.
Test
First of all, use should use appropriate tool for parsing HTML (XML in general), regex is very bad idea for that.
But if you HAVE TO use regex, I’d suggest such pattern:
(?s)<script.+?</script>
Explanation:
(?s)
– single line mode:.
matches newline<script
– match<script
literally.+?
– match one or more of any character (including newline), non-greedy (as least as possible)</script>
– match</script>
literallyDemo