[已解决]正则提取字符串的问题,请大家帮忙看看,谢谢
本帖最后由 风过无痕 于 2017-12-28 18:14 编辑<add key="ConnectionString" value="server=localhost;database=cd;User ID=sa;password=Test2017" />
<add key="ConnectionString2" value="server=localhost;database=dz;User ID=sa;password=Test2017" />
<add key="AciveTimeout" value="30" />
<add key="RefreshTimeout" value="20" />
<add key="currentVersion" value="Version2.1 20120408" />
<add key="lifeCycle" value="30" />
<add key="validPw" value="03FB6D2706C1DB1771D3886267"/>
<add key="plateImgPath" value="http:\\192.168.1.13\videos\"/>
<add key="MJDataBaseConnectString" value="server=192.168.1.134;database=MJDataBase;User ID=sa;password=Test2017" />
红色替换的数据为
192.168.5.12
kxp
admin
admin2017
"03FB6D2706C1DB1771D388T453"
蓝色替换数据为
192.168.5.13
mjxt
mj
admin2017
将红色和蓝色字符串提取出来(替换),因为所在行不固定,整行替换的话怕有问题,能不能用正则实现提取呢?
正则实在不懂,各位帮帮忙吧,谢谢!
谢谢afan版主的帮助!!! 纯体力活……
Local $sSource = _
'<add key="ConnectionString" value="server=localhost;database=cd;User ID=sa;password=Test2017" />' & @CRLF & _
' <add key="ConnectionString2" value="server=localhost;database=dz;User ID=sa;password=Test2017" />' & @CRLF & _
' <add key="AciveTimeout" value="30" />' & @CRLF & _
' <add key="RefreshTimeout" value="20" />' & @CRLF & _
' <add key="currentVersion" value="Version2.1 20120408" />' & @CRLF & _
' <add key="lifeCycle" value="30" /> ' & @CRLF & _
' <add key="validPw" value="03FB6D2706C1DB1771D3886267"/>' & @CRLF & _
'<add key="plateImgPath" value="http:\\192.168.1.13\videos\"/>' & @CRLF & _
'<add key="MJDataBaseConnectString" value="server=192.168.1.134;database=MJDataBase;User ID=sa;password=Test2017" />'
;~ MsgBox(0, '源字符串', $sSource)
Local $sR1 = '192.168.5.12'
Local $sR2 = 'kxp'
Local $sR3 = 'admin'
Local $sR4 = 'admin2017'
Local $sR5 = '03FB6D2706C1DB1771D388T453'
Local $sR6 = '192.168.5.13'
Local $sR7 = 'mjxt'
Local $sR8 = 'mj'
Local $sR9 = 'admin2017'
Local $sSRERe = StringRegExpReplace($sSource, '("ConnectionString" value="server=)([^;]+)(;database=)([^;]+)(;User ID=)([^;]+)(;password=)([^"]+)("[\S\s]+?validPw" value=")([^"]+)("/>[\S\s]+?"server=)([^;]+)(;database=)([^;]+)(;User ID=)([^;]+)(;password=)([^"]+)(?=")', '${1}' & $sR1 & '${3}' & $sR2 & '${5}' & $sR3 & '${7}' & $sR4 & '${9}' & $sR5 & '${11}' & $sR6 & '${13}' & $sR7 & '${15}' & $sR8 & '${17}' & $sR9)
MsgBox(0, '替换结果', $sSRERe) A版好强大
{:face (88):}
页:
[1]