我正在尝试使用Javascript Regex从文件中提取子字符串。这是文件的一部分:
Version=2
Format=jpg
Size=1280x960
Date=2013/05/08
Time=23:49:40
Value=250000
我想只提取Version
并Value
从文本文件。我尝试使用此方法提取版本,但它不返回任何内容。
$('.Content').html().match(/^Version\:(.*)$/g);
$('.Content').html()
包含整个文本文件。
您必须删除锚点或使用m
标志:
$('.Content').html().match(/Version=(.*)/g);
或者
$('.Content').html().match(/^Version=(.*)$/gm);
编辑:对于捕获值和版本,您可以执行以下操作:
$('.Content').html().match(/Version=(.*)|Value=(.*)/g);
您将获得版本$1
和价值$2
见演示
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句