请教个正则问题。。。。[已解决]
本帖最后由 xzxnovice 于 2013-11-5 08:19 编辑[{"type":"hidden","name":"410acec","id":"t0ecf6c9"},{"type":"hidden","name":"39457e2","id":"s66045f2"},{"type":"hidden","name":"_t","value":1383019930},{"type":"hidden","name":"dfbe04c","value":"abcad67"}]想把nameid和namevalue
分两组匹配出来,放到数组
410acect0ecf6c9
39457e2 s66045f2
_t 1383019930
dfbe04c abcad67
自己写成这样,$exp = StringRegExp($html, '\"name\":\"(.*?)\",\"value\":\"(.*?)\"',4)
但不是我想要的结果 现学现卖~http://www.autoitx.com/thread-39943-1-1.html
跟A版真学到太多~(?:name|id|value)":\W?(.*?)(?:"|}) json数据不是有支持库吗? 回复 2# haijie1223
谢谢,某些情况可以的,但我忘了说上面的数组次序会打乱的,name id value内容随机 。这样匹配出来来是分不出哪 个是id哪个是value..,最好整组匹配出来 json数据不是有支持库吗?
annybaby 发表于 2013-10-30 01:54 http://www.autoitx.com/images/common/back.gif
正则搞不定再考虑json操作,au也不是直接支持json,操作起来还是有点麻烦。 回复 4# xzxnovice
你把顺序打乱试试呗~~ 回复 4# xzxnovice
相邻的应该是一组吧 需要的结果并无包含关系,所以个人认为LZ用4的匹配模式并不方便~ 正如LS阿杰所说,相邻的应该是一组,我也认为大致如此,只是并非仅相邻,还应该是“双单”的数组下标顺序。
如果是需要更精准一些,不妨增加提取“name id value”,修改下阿杰的即可:(?i)(name|id|value)":"?(.*?)["}] 本帖最后由 xzxnovice 于 2013-10-30 14:53 编辑
回复 8# afan
这个可以,收下。。。。谢谢各位
另外:
我用4的目的是这样的,可能我对4的功能不够理解。
先捉name id 这组$exp = StringRegExp($html, '\"name\":\"(.*?)\",\"id\":\"(.*?)\"', 4)
If @error = 0 Then
For $i=0 To UBound($Exp)-1
$tmpary=$exp[$i]
For $j=0 To UBound($tmpary)-1
ConsoleWrite($tmpary[$j]&@CRLF)
Next
ConsoleWrite(@CRLF)
Next
EndIf 结果为"name":"410acec","id":"t0ecf6c9"
410acec
t0ecf6c9
"name":"39457e2","id":"s66045f2"
39457e2
s66045f2然后捉name value 的$exp = StringRegExp($html, '\"name\":\"(.*?)\",\"value\":\"(.*?)\"', 4)
If @error = 0 Then
For $i=0 To UBound($Exp)-1
$tmpary=$exp[$i]
For $j=0 To UBound($tmpary)-1
ConsoleWrite($tmpary[$j]&@CRLF)
Next
ConsoleWrite(@CRLF)
Next
EndIf由于正则不对,所以得不到我想要的结果,把中间一段的包含进去。"name":"410acec","id":"t0ecf6c9"},{"type":"hidden","name":"39457e2","id":"s66045f2"},{"type":"hidden","name":"_t","value":1383019930},{"type":"hidden","name":"dfbe04c","value":"abcad67"
410acec","id":"t0ecf6c9"},{"type":"hidden","name":"39457e2","id":"s66045f2"},{"type":"hidden","name":"_t","value":1383019930},{"type":"hidden","name":"dfbe04c
abcad67预期是这样的"name":"_t","value":1383019930
_t
1383019930
"name":"dfbe04c","value":"abcad67"
dfbe04c
abcad67应该修改正则所以达到目的吧,只把紧贴name id 和name value匹配出来,能否在我的思路上帮我改改。。 需要的结果并无包含关系,所以个人认为LZ用4的匹配模式并不方便~ 正如LS阿杰所说,相邻的应该是一组,我也认 ...
afan 发表于 2013-10-30 12:02 http://www.autoitx.com/images/common/back.gif$exp = StringRegExp($html, '"name":"([^}]*?)","value":"?(.*?)"?}', 4)
If @error = 0 Then
For $i = 0 To UBound($exp) - 1
$tmpary = $exp[$i]
For $j = 0 To UBound($tmpary) - 1
ConsoleWrite($tmpary[$j] & @CRLF)
Next
ConsoleWrite(@CRLF)
Next
EndIf
$exp = StringRegExp($html, '"name":"([^}]*?)","id":"?(.*?)"?}', 4)
If @error = 0 Then
For $i = 0 To UBound($exp) - 1
$tmpary = $exp[$i]
For $j = 0 To UBound($tmpary) - 1
ConsoleWrite($tmpary[$j] & @CRLF)
Next
ConsoleWrite(@CRLF)
Next
EndIf
"name":"_t","value":1383019930}
_t
1383019930
"name":"dfbe04c","value":"abcad67"}
dfbe04c
abcad67
"name":"410acec","id":"t0ecf6c9"}
410acec
t0ecf6c9
"name":"39457e2","id":"s66045f2"}
39457e2
s66045f2改成这样是我想要的了,但不知是否精准。。 一看就是json 数据,直接用json支持库就好了啊。 $sTemp = '[{"type":"hidden","name":"410acec","id":"t0ecf6c9"},{"type":"hidden","name":"39457e2","id":"s66045f2"},{"type":"hidden","name":"_t","value":1383019930},{"type":"hidden","name":"dfbe04c","value":"abcad67"}]'
; 去源字符串尾巴
$sTemp = StringTrimRight($sTemp, 2)
; 把数据按节拆分成数组
$aTemp = StringSplit($sTemp, "},{", 1)
; 遍历每一节
For $sTemp_Curr In $aTemp
If StringRegExp($sTemp_Curr, 'name":"(.*)","id":("?.*"?)') Then
$aTempReg = StringRegExp($sTemp_Curr, 'name":"(.*)","id":("?.*"?)', 1)
ConsoleWrite("name:" & $aTempReg & " id:" & $aTempReg & @CRLF)
ElseIf StringRegExp($sTemp_Curr, 'name":"(.*)","value":("?.*"?)') Then
$aTempReg = StringRegExp($sTemp_Curr, 'name":"(.*)","value":("?.*"?)', 1)
ConsoleWrite("name:" & $aTempReg & " value:" & $aTempReg & @CRLF)
Else
; 没有匹配到
EndIf
Next 回复 12# mbdnmt
也行。谢谢!
页:
[1]