[已解决]利用正则如何提取指定的字符?
本帖最后由 showshow 于 2012-5-25 08:18 编辑Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e(Balanced)
Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347(Power buttons and lid)
Power Setting GUID: 5ca83367-6e45-459f-a27b-476b1d01c936(Lid close action)
Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down
Current AC Power Setting Index: 0x00000001
Current DC Power Setting Index: 0x00000001
Power Setting GUID: 7648efa3-dd9c-4e3e-b566-50f929386280(Power button action)
Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down
Current AC Power Setting Index: 0x00000001
Current DC Power Setting Index: 0x00000001
Power Setting GUID: 96996bc0-ad50-47ec-923b-6f41874dd9eb(Sleep button action)
Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down
Current AC Power Setting Index: 0x00000001
Current DC Power Setting Index: 0x00000001
Power Setting GUID: a7066653-8d6c-40a8-910e-a1f54b84c7e5(Start menu power button)
Possible Setting Index: 000
Possible Setting Friendly Name: Sleep
Possible Setting Index: 001
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 002
Possible Setting Friendly Name: Shut down
Current AC Power Setting Index: 0x00000000
Current DC Power Setting Index: 0x00000000
想提取
Power Setting GUID: 7648efa3-dd9c-4e3e-b566-50f929386280(Power button action)
Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down
Current AC Power Setting Index: 0x00000001
Current DC Power Setting Index: 0x00000001
中的红色的1值,用StringRegExp怎么实现啊,正则搞不懂~汗
============感谢各位大大============== 看来大牛们都给楼主考倒了, 恭喜楼主了! 回复 2# user3000
是太简单了还是~? (?msi)Power button action\).*?Current.*?(0x[[:xdigit:]]+).*?(0x[[:xdigit:]]+) 本帖最后由 user3000 于 2012-5-22 16:49 编辑
回复 3# showshow
只获取 '1' ?? 很少见用正则来这样匹配单字的!
也许是我想多了! 你有'特殊'用途吧!
补充: 如果是这样, 你应该说, 如何用正则来判断该处的两个十六进制数的最后一位是否为'1' ! 本帖最后由 lixiaolong 于 2012-5-22 18:05 编辑
#include <Array.au3>
Local $Str = _
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e(Balanced)' & @CRLF & _
'Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347(Power buttons and lid)' & @CRLF & _
' Power Setting GUID: 5ca83367-6e45-459f-a27b-476b1d01c936(Lid close action)' & @CRLF & _
' Possible Setting Index: 000' & @CRLF & _
' Possible Setting Friendly Name: Do nothing' & @CRLF & _
' Possible Setting Index: 001' & @CRLF & _
' Possible Setting Friendly Name: Sleep' & @CRLF & _
' Possible Setting Index: 002' & @CRLF & _
' Possible Setting Friendly Name: Hibernate' & @CRLF & _
' Possible Setting Index: 003' & @CRLF & _
' Possible Setting Friendly Name: Shut down' & @CRLF & _
' Current AC Power Setting Index: 0x00000001' & @CRLF & _
' Current DC Power Setting Index: 0x00000002' & @CRLF & @CRLF & _
' Power Setting GUID: 7648efa3-dd9c-4e3e-b566-50f929386280(Power button action)' & @CRLF & _
' Possible Setting Index: 000' & @CRLF & _
' Possible Setting Friendly Name: Do nothing' & @CRLF & _
' Possible Setting Index: 001' & @CRLF & _
' Possible Setting Friendly Name: Sleep' & @CRLF & _
' Possible Setting Index: 002' & @CRLF & _
' Possible Setting Friendly Name: Hibernate' & @CRLF & _
' Possible Setting Index: 003' & @CRLF & _
' Possible Setting Friendly Name: Shut down' & @CRLF & _
' Current AC Power Setting Index: 0x00000003' & @CRLF & _
' Current DC Power Setting Index: 0x00000002' & @CRLF & @CRLF & _
' Power Setting GUID: 96996bc0-ad50-47ec-923b-6f41874dd9eb(Sleep button action)' & @CRLF & _
' Possible Setting Index: 000' & @CRLF & _
' Possible Setting Friendly Name: Do nothing' & @CRLF & _
' Possible Setting Index: 001' & @CRLF & _
' Possible Setting Friendly Name: Sleep' & @CRLF & _
' Possible Setting Index: 002' & @CRLF & _
' Possible Setting Friendly Name: Hibernate' & @CRLF & _
' Possible Setting Index: 003' & @CRLF & _
' Possible Setting Friendly Name: Shut down' & @CRLF & _
' Current AC Power Setting Index: 0x00000001' & @CRLF & _
' Current DC Power Setting Index: 0x00000001' & @CRLF & @CRLF & _
' Power Setting GUID: a7066653-8d6c-40a8-910e-a1f54b84c7e5(Start menu power button)' & @CRLF & _
' Possible Setting Index: 000' & @CRLF & _
' Possible Setting Friendly Name: Sleep' & @CRLF & _
' Possible Setting Index: 001' & @CRLF & _
' Possible Setting Friendly Name: Hibernate' & @CRLF & _
' Possible Setting Index: 002' & @CRLF & _
' Possible Setting Friendly Name: Shut down' & @CRLF & _
' Current AC Power Setting Index: 0x00000000' & @CRLF & _
' Current DC Power Setting Index: 0x00000000'
Local $Test = StringRegExp($str, '(?s)b566.*?0x\d{7}(\d).*?\d{7}(\d)', 3)
If Not @Error Then _ArrayDisplay($Test, UBound($Test))
回复 6# lixiaolong
十六进制的数值, 有可能是 A到F 的字母, 所以还是像 3Mile 老大一样用 [[:xdigit:]] 最稳当. 回复 4# 3mile
一直不知道 [:xdigit:] [:lower:] 等用法, 原来是要跟 [] 一起用呀!
嘻嘻, 以前测试这些东西老得不出结果, 原来是这么回事呀! 本帖最后由 showshow 于 2012-5-23 17:16 编辑
回复 4# 3mile Run(@ComSpec & " /c " & 'powercfg /q >2.txt', "", @SW_HIDE)
$a=FileRead("2.txt")
$p=StringRegExp($a,"(?msi)Power button action\).*?Current.*?(0x[[:xdigit:]]+).*?(0x[[:xdigit:]]+)",2)
If $p=$p Then
IniWrite("temp2.ini","Power buttons and lid","Power button action",StringRight($p,1))
Else
IniWrite("temp2.ini","Power buttons and lid","Power button action","false")
EndIf为什么第一次运行会出错啊,好像是无效数组,第二次再运行就好,不知什么情况?
我的是Win7系统下的,贴上“2.txt” 回复 9# showshow Run(@ComSpec & " /c " & 'powercfg /q >2.txt', "", @SW_HIDE)
sleep(600)
$a=FileRead("2.txt")
$p=StringRegExp($a,"(?msi)Power button action\).*?Current.*?(0x[[:xdigit:]]+).*?(0x[[:xdigit:]]+)",2)
If $p=$p Then
IniWrite("temp2.ini","Power buttons and lid","Power button action",StringRight($p,1))
Else
IniWrite("temp2.ini","Power buttons and lid","Power button action","false")
EndIf加个延迟就好了~
页:
[1]