找回密码
 加入
搜索
查看: 4376|回复: 10

[AU3基础] [已解决]利用正则如何提取指定的字符?

  [复制链接]
发表于 2012-5-22 12:35:51 | 显示全部楼层 |阅读模式
本帖最后由 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怎么实现啊,正则搞不懂~汗


============感谢各位大大==============
发表于 2012-5-22 14:45:33 | 显示全部楼层
看来大牛们都给楼主考倒了, 恭喜楼主了!
 楼主| 发表于 2012-5-22 15:50:06 | 显示全部楼层
回复 2# user3000


   是太简单了还是~?
发表于 2012-5-22 16:02:09 | 显示全部楼层
(?msi)Power button action\).*?Current.*?(0x[[:xdigit:]]+).*?(0x[[:xdigit:]]+)

评分

参与人数 2金钱 +58 贡献 +5 收起 理由
lixiaolong + 30
user3000 + 28 + 5 谢谢,是这么用滴: [[:xdigit:]] 一直用 ...

查看全部评分

发表于 2012-5-22 16:36:47 | 显示全部楼层
本帖最后由 user3000 于 2012-5-22 16:49 编辑

回复 3# showshow

只获取 '1' ?? 很少见用正则来这样匹配单字的!
也许是我想多了! 你有'特殊'用途吧!

补充: 如果是这样, 你应该说, 如何用正则来判断该处的两个十六进制数的最后一位是否为'1' !
发表于 2012-5-22 18:03:48 | 显示全部楼层
本帖最后由 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))

评分

参与人数 1贡献 +2 收起 理由
user3000 + 2 老大, 十六进制数, 有可能是A-F等字母哦!

查看全部评分

发表于 2012-5-22 18:40:03 | 显示全部楼层
回复 6# lixiaolong

十六进制的数值, 有可能是 A到F 的字母, 所以还是像 3Mile 老大一样用 [[:xdigit:]] 最稳当.

评分

参与人数 1金钱 +30 收起 理由
lixiaolong + 30 谢谢提醒!

查看全部评分

发表于 2012-5-22 18:42:22 | 显示全部楼层
回复 4# 3mile

一直不知道 [:xdigit:] [:lower:] 等用法, 原来是要跟 [] 一起用呀!
嘻嘻, 以前测试这些东西老得不出结果, 原来是这么回事呀!

评分

参与人数 1金钱 +35 收起 理由
3mile + 35 3000兄谦虚了

查看全部评分

 楼主| 发表于 2012-5-23 17:13:20 | 显示全部楼层
本帖最后由 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[1]=$p[2] Then
        IniWrite("temp2.ini","Power buttons and lid","Power button action",StringRight($p[1],1))
Else
        IniWrite("temp2.ini","Power buttons and lid","Power button action","false")
EndIf
为什么第一次运行会出错啊,好像是无效数组,第二次再运行就好,不知什么情况?
我的是Win7系统下的,贴上“2.txt”

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2012-5-23 17:36:10 | 显示全部楼层
回复 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[1]=$p[2] Then
        IniWrite("temp2.ini","Power buttons and lid","Power button action",StringRight($p[1],1))
Else
        IniWrite("temp2.ini","Power buttons and lid","Power button action","false")
EndIf
加个延迟就好了~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 02:52 , Processed in 0.083057 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表