如何用正则获取指定内容?
字符串如下:var ILData = new Array("A1","B1", "C1", "D1", "E1"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); } 如何用正则分别获取A1,B1,C1,D1和E1? #include<array.au3>$String='var ILData = new Array("A1","B1", "C1", "D1", "E1","爱谁谁","跑不了你的"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); }'
$strtemp=StringRegExp($string,'\("[^()]*?\)',3)
;_ArrayDisplay($strtemp)
If IsArray($strtemp) Then $strfin=StringRegExp($strtemp,'"[^"]*?"',3)
_ArrayDisplay($strfin) 如果我没有理解错的话,楼主代码框里的是字符串。#include <array.au3>
$str='"var ILData = new Array("A1","B1", "C1", "D1", "E1"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); } "'
$arr=StringRegExp($str,'\"\w\d\"',3)
_ArrayDisplay($arr) 本帖最后由 l4ever 于 2010-4-21 22:20 编辑
如果我没有理解错的话,楼主代码框里的是字符串。
3mile 发表于 2010-4-21 22:09 http://www.autoitx.com/images/common/back.gif
A1,B1,C1,D1和E1都不是规定的,可能是数字也可能是中文.
也可能不止是2个字符 水木子呢?帮我看看? #include<array.au3>
$String='var ILData = new Array("A1","B1", "C1", "D1", "E1","爱谁谁","跑不了你的"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); }'
$ArrayTemp = StringRegExp($String,'new Array\((.*)\); if',3)
If IsArray($ArrayTemp) Then $ArrayTemp = $ArrayTemp
$Array = StringRegExp($ArrayTemp,'"(.+?)"',3)
_ArrayDisplay($Array) #include
$String='var ILData = new Array("A1","B1", "C1", "D1", "E1","爱谁谁","跑不了你的"); if (ty ...
caodongchun 发表于 2010-4-22 01:39 http://www.autoitx.com/images/common/back.gif
有点眉目,但是如果其中某个字符串可能是空白的,
你的写法返回的是", 建议楼主多举例几种字符串的结构变化,这样方面书写表达式。 取引号内的字符
#include <array.au3>
$str='var ILData = new Array("A1","B1", "C1", "D1", "E1"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); } '
$arr=StringRegExp($str,'"[^"]*"',3)
_ArrayDisplay($arr)
本帖最后由 caodongchun 于 2010-4-22 16:58 编辑
#include<array.au3>
$String='var ILData = new Array("A1","B1", "C1", "D1", "E1","爱谁谁"," ","","跑不了你的",""); if (typeof(ILData_callback) != "undefined") { ILData_callback(); }'
$ArrayTemp = StringRegExp($String,'new Array\((.*)\); if',3)
If IsArray($ArrayTemp) Then $ArrayTemp = $ArrayTemp
$Array = StringRegExp($ArrayTemp,'(?U)"(.*)"',3)
_ArrayDisplay($Array)
MsgBox(0,0,_ArrayToString($Array)) 取引号内的字符
doshowyam 发表于 2010-4-22 13:16 http://www.autoitx.com/images/common/back.gif
似乎不需要undefined
页:
[1]