[已解决]正则表达式提取特定内容,请大神指导
本帖最后由 zhouhaijin 于 2015-1-25 11:46 编辑Decompress, compress len=, orig len= CFtdcUserApiImplBase::HandlePackage FTDC PACKAGE HEADER Version,Chain,SequenceSeries,TransactionId,SequenceNumber FieldCount,FTDCContentLength,RequestId FTDC PACKAGE CONTENT START FIELD START [IF1502] [01:42:35] [0] FIELD END FIELD START [3609.600000] [50] [3609.800000] [50] FIELD END FTDC PACKAGE CONTENT END
取红色部分和前面[的英文],前面的英文是固定的,最好是根据前面的英文取后面的值 已收藏,等大大来上课 .. \[(+)\]\[\d\]\[(.*?)\] Local $Str = ''
$Str &= 'Decompress, compress len=, orig len= CFtdcUserApiImplBase::HandlePackage FTDC PACKAGE HEADER Version,Chain,SequenceSeries,TransactionId,SequenceNumber FieldCount,FTDCContentLength,RequestId FTDC PACKAGE CONTENT START FIELD START FIELD END FIELD [CFTDMarketDataBestPriceFi'
$Str &= 'eld] START FIELD END FTDC PACKAGE CONTENT END' & @CRLF & @CRLF & @CRLF
MsgBox(0, '', _GetVal($str, 'InstrumentID') & @LF & _
_GetVal($str, 'UpdateTime') & @LF & _
_GetVal($str, 'UpdateMillisec') & @LF & _
_GetVal($str, 'BidPrice1') & @LF & _
_GetVal($str, 'BidVolume1') & @LF & _
_GetVal($str, 'AskPrice1') & @LF & _
_GetVal($str, 'AskVolume1'))
Func _GetVal($str, $sName)
Local $aSR = StringRegExp($str, '\[' & $sName & '\]\[\d+\]\[(.+?)\]', 1)
If Not @Error Then Return $aSR
EndFunc ;==>_GetVal
是想要这样的效果么???
#include <Array.au3>
Local $file = FileOpen(@ScriptDir&"\1.txt", 0)
If $file = -1 Then Exit
Local $chars = FileRead($file)
If @error = -1 Then Exit
Local $res = StringRegExp($chars,"\w{9,15}(?=\]\[)|(?:\[\d\]\[)(\w+.*?)(?=]\s)",3)
If Not @error Then _arraydisplay($res,'test')
FileClose($file)
乱写一通,大神勿贱笑啊。。 回复 4# afan
谢谢超版 回复 3# athland5013
谢谢帮忙 回复 5# 半芯竹
谢谢 回复 4# afan
就是想要这个效果 进帖学习,天天向上~
页:
[1]