I’m trying to extract UA-123456-7 from the following Google Analytic using regular expression. I think I’m too close, but I’m not sure it is even possible.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-123456-7");
pageTracker._trackPageview();
</script>
Here is what I get when I run at http://www.regular-expressions.info
Regex: ^[<>%\w_\/.:;()\+-=?"]*(.*?)[<>\w_.;()]*$
Replacement text: $1
Result: gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));var pageTracker = _gat._getTracker("UA-140422-1"
Could someone please shed the light? Thanks in Advance!
Why don’t you use a substring ?
Find the position of the string “_getTracker(” -> Pos A
same for string “)” -> Pos B
And substring between Pos A and Pos B.
Is that helpfull ?