网店 发表于 2012-4-28 13:12:25

已解决正则代码表述问题

本帖最后由 网店 于 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 的正则该怎么处理?

kevinch 发表于 2012-4-28 13:24:59

(?:^|[\r\n])((\d+(\.\d+)*,){2}(\d+(\.\d+)*))这样试下

网店 发表于 2012-4-28 13:48:11

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

不正确

shqf 发表于 2012-4-28 13:55:05

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

kevinch 发表于 2012-4-28 14:47:47

回复 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 14:51:47

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

网店 发表于 2012-4-28 15:52:12

回复 4# shqf


    嗯
页: [1]
查看完整版本: 已解决正则代码表述问题