Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式-从Google分析脚本中提取跟踪ID_Regex - Fatal编程技术网

Regex 正则表达式-从Google分析脚本中提取跟踪ID

Regex 正则表达式-从Google分析脚本中提取跟踪ID,regex,Regex,我正在尝试使用正则表达式从以下Google分析中提取UA-123456-7。我想我离得太近了,但我不确定这是否可能 <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google

我正在尝试使用正则表达式从以下Google分析中提取UA-123456-7。我想我离得太近了,但我不确定这是否可能

<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>

var gaJsHost=((“https:==document.location.protocol)?”https://ssl." : "http://www.");
write(unescape(“%3Cscript src=”+gaJsHost+“google analytics.com/ga.js”type='text/javascript'%3E%3C/script%3E”);
var pageTracker=_gat._getTracker(“UA-123456-7”);
页面跟踪器。_trackPageview();
这是我跑步时得到的

正则表达式:
^[%\w\u\/.:;()\+-=?“]*(.*)[\ w\u\.]*$

替换文本:
$1

结果:
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=\u gat.\u getTracker(“UA-140422-1”


有人能帮我点灯吗?提前谢谢!

为什么不使用子字符串

找到字符串“\u getTracker”(->位置A)的位置

与字符串“)”->位置B相同

以及位置A和位置B之间的子字符串


这有帮助吗?

这是我的结论。谢谢你的提示。text=text.replace(//[\r\n\s]+/g');//删除新行字符text=text.replace(//^(.*UA/g');//最多删除UA text=text.replace(//['](.?$/g');//删除其余字符