已解决正则代码表述问题
本帖最后由 网店 于 2012-4-28 15:56 编辑8.30,8.31,8.23,8.32,8.21
7.31,0,6.73,6.72,9.31
正则取前三组数字
这个 0 的正则该怎么处理? (?:^|[\r\n])((\d+(\.\d+)*,){2}(\d+(\.\d+)*))这样试下 本帖最后由 网店 于 2012-4-28 13:50 编辑
回复 2# kevinch
Local $Str = _
'8.30,8.31,8.23,8.32,8.21' & @CRLF & _
'7.31,0,6.73,6.72,9.31' & @CRLF & _
'9.31,9.37,6.27,1.62,0.11'
$res = StringRegExp($Str,"(?:^|[\r\n])((\d+(\.\d+)*,){2}(\d+(\.\d+)*))",1)
If Not @error Then _ArrayDisplay($res)
不正确 #include <Array.au3>
Local $Str = _
'8.30,8.31,8.23,8.32,8.21' & @CRLF & _
'7.31,0,6.73,6.72,9.31'
Local $Test = StringRegExp($str, '(?m)(.+),[^,]+,[^,]+$', 3)
_ArrayDisplay($Test) 回复 3# 网店 #include <array.au3>
Local $Str = _
'8.30,8.31,8.23,8.32,8.21' & @CRLF & _
'7.31,0,6.73,6.72,9.31' & @CRLF & _
'9.31,9.37,6.27,1.62,0.11'
$res = StringRegExp($Str,"(?:^|[\r\n])((\d+(\.\d+)*,){2}(\d+(\.\d+)*))",3)
If Not @error Then
;_ArrayDisplay($res)
For $n=0 To UBound($res)-1 Step 5
ConsoleWrite($res[$n]&@CRLF)
Next
EndIf 本帖最后由 lixiaolong 于 2012-4-28 15:29 编辑
楼主的问题真让人难懂...
Local $Str = _
'8.30,8.31,8.23,8.32,8.21' & @CRLF & _
'7.31,0,6.73,6.72,9.31' & @CRLF
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExp($str, '[\d\.,]+[\r\n]+.*?,([^,]+)', 1)
MsgBox(0, '', $Test)
Local $Str = _
'8.30,8.31,8.23,8.32,8.21' & @CRLF & _
'7.31,0,6.73,6.72,9.31' & @CRLF
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExpReplace($Str, '(.+\r\n[\d\.,]+,)(\d+),', '\1')
MsgBox(0, '', $Test)
;Local $Test = StringRegExpReplace($str, '(.+\r\n[\d\.,]+,)(\d+)(,)', '\1\3')
;MsgBox(0, '', $Test)
回复 4# shqf
嗯
页:
[1]