求个正则,提取指定字符串,谢谢(已解决)
本帖最后由 dearmb 于 2011-3-16 15:47 编辑<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Orid.Management.SOHO.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Orid.Management.SOHO.Properties.Settings>
<setting name="DefaultFontFile" serializeAs="String">
<value>o-rid Overline</value>
</setting>
<setting name="ColorIndex" serializeAs="String">
<value>0</value>
</setting>
<setting name="ServerAddress" serializeAs="String">
<value>192.168.163.92</value>
</setting>
<setting name="ServerName" serializeAs="String">
<value>練習#4</value>
</setting>
<setting name="ViewVersion" serializeAs="String">
<value> (Version 30.1)</value>
</setting>
<setting name="CompanyMasterContoinString" serializeAs="String">
<value>192.168.163.21</value>
</setting>
</Orid.Management.SOHO.Properties.Settings>
</applicationSettings>
</configuration>
提取红色的版本号,Version 30.1这句内容,十分感谢……
如果能把表达式再给个说明就更好啦,以后就可以自己改了,谢谢 本帖最后由 lixiaolong 于 2011-3-9 18:54 编辑
StringRegExp
(?s)<.+"ViewVersion".+>.+\s\((.*?)(?=\)</value>) 貌似只要提取小括号里的内容就可以了吧
$a=" <value> (Version 30.1)</value>"
$array = StringRegExp($a, '\((.*)\)', 3)
for $i = 0 to UBound($array) - 1
msgbox(0, "正则表达式选项 3 测试 " & $i, $array[$i])
Next 本帖最后由 dearmb 于 2011-3-9 19:24 编辑
StringRegExp
(?s).+\s\((.*?)(?=\))
lixiaolong 发表于 2011-3-9 18:51 http://autoitx.com/images/common/back.gif
呃……没看懂,能不能写全点?
$str=FileRead("D:\EntrySystems\Line8\SOHO.exe.config")
$str2=StringRegExp($str,'(?s)<.+"ViewVersion".+>.+\s\((.*?)(?=\)</value>)')
MsgBox(0,"",$str)
MsgBox(0,"",$str2)
是这样吗? 貌似只要提取小括号里的内容就可以了吧
$a="(Version 30.1)"
$array = StringRegExp($a, '\((.*)\)', 3 ...
xyold1 发表于 2011-3-9 18:52 http://autoitx.com/images/common/back.gif
不行吧,上面那个字符串有好多小括号的内容呢 回复 4# dearmb $Str = _
'<?xml version="1.0" encoding="utf-8" ?>' & @CRLF & _
'<configuration>' & @CRLF & _
' <configSections>' & @CRLF & _
' <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >' & @CRLF & _
' <section name="Orid.Management.SOHO.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />' & @CRLF & _
' </sectionGroup>' & @CRLF & _
' </configSections>' & @CRLF & _
' <applicationSettings>' & @CRLF & _
' <Orid.Management.SOHO.Properties.Settings>' & @CRLF & _
' <setting name="DefaultFontFile" serializeAs="String">' & @CRLF & _
' <value>o-rid Overline</value>' & @CRLF & _
' </setting>' & @CRLF & _
' <setting name="ColorIndex" serializeAs="String">' & @CRLF & _
' <value>0</value>' & @CRLF & _
' </setting>' & @CRLF & _
' <setting name="ServerAddress" serializeAs="String">' & @CRLF & _
' <value>192.168.163.92</value>' & @CRLF & _
' </setting>' & @CRLF & _
' <setting name="ServerName" serializeAs="String">' & @CRLF & _
' <value>練習#4</value>' & @CRLF & _
' </setting>' & @CRLF & _
' <setting name="ViewVersion" serializeAs="String">' & @CRLF & _
' <value> (Version 30.1)</value>' & @CRLF & _
' </setting>' & @CRLF & _
' <setting name="CompanyMasterContoinString" serializeAs="String">' & @CRLF & _
' <value>192.168.163.21</value>' & @CRLF & _
' </setting>' & @CRLF & _
' </Orid.Management.SOHO.Properties.Settings>' & @CRLF & _
' </applicationSettings>' & @CRLF & _
'</configuration>' & @CRLF & @CRLF
$Test = StringRegExp($str, '(?s)<.+"ViewVersion".+>.+\s\((.*?)(?=\)</value>)', 3)
MsgBox(0,0,$Test) 回复dearmb
lixiaolong 发表于 2011-3-9 19:30 http://autoitx.com/images/common/back.gif
爱死你了~~ 本帖最后由 lixiaolong 于 2011-3-9 19:53 编辑
回复 4# dearmb
StringRegExp ( "字符串", "表达式" [, 标志 ] [, 偏移量 ] ] )
StringRegExp($str, '(?s)<.+"ViewVersion".+>.+\s\((.*?)(?=\)</value>)', 3); 返回全局匹配的数组.
(?s) = 匹配任意字符,包括换行.
. = 匹配任何的单字符 (除换行以外).
+ = 重复一次或更多次.
.*? = 匹配任何的单字符 (除换行以外),重复零次或更多次,重复零次或一次.
(?=\)</value>) = 匹配 ")</value>" 前面的位置.
\s 不用也行. 回复 7# dearmb
你嫁给我吧!{:face (88):} 回复dearmb
你嫁给我吧!
lixiaolong 发表于 2011-3-9 19:47 http://autoitx.com/images/common/back.gif
男人你都要?无耻啊……{:face (394):} 回复 10# dearmb
我是开玩笑的,呵呵{:face (239):} 路过,顶一个{:face (332):} 直接搜索,Version,然后取其后面的4个字符...我一般都是这么整的... 直接搜索,Version,然后取其后面的4个字符...我一般都是这么整的...
www378660084 发表于 2011-3-10 02:05 http://autoitx.com/images/common/back.gif
我原来是想那么弄,但此段字符串有N个Version ,没有办法 直接搜索,Version,然后取其后面的4个字符...我一般都是这么整的...
www378660084 发表于 2011-3-10 02:05 http://autoitx.com/images/common/back.gif
我原来是想那么弄,但此段字符串有N个Version ,没有办法
页:
[1]