l4ever 发表于 2010-4-21 22:02:16

如何用正则获取指定内容?

字符串如下:var ILData = new Array("A1","B1", "C1", "D1", "E1"); if (typeof(ILData_callback) != "undefined") { ILData_callback(); } 如何用正则分别获取A1,B1,C1,D1和E1?

3mile 发表于 2010-4-21 22:02:17

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

3mile 发表于 2010-4-21 22:09:12

如果我没有理解错的话,楼主代码框里的是字符串。#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:17:27

本帖最后由 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个字符

l4ever 发表于 2010-4-21 23:59:51

水木子呢?帮我看看?

caodongchun 发表于 2010-4-22 01:39:21

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

l4ever 发表于 2010-4-22 12:51:05

#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

有点眉目,但是如果其中某个字符串可能是空白的,
你的写法返回的是",

水木子 发表于 2010-4-22 13:11:25

建议楼主多举例几种字符串的结构变化,这样方面书写表达式。

doshowyam 发表于 2010-4-22 13:16:30

取引号内的字符
#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:55:28

本帖最后由 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))

caodongchun 发表于 2010-4-22 16:59:40

取引号内的字符
doshowyam 发表于 2010-4-22 13:16 http://www.autoitx.com/images/common/back.gif

似乎不需要undefined
页: [1]
查看完整版本: 如何用正则获取指定内容?