Regex 从文本中提取数字信息

Regex 从文本中提取数字信息,regex,pcre,autoit,Regex,Pcre,Autoit,我需要从文本中提取数字信息 Ready State: CTYG Work Request #: 2880087 General Job Address Contact Work Request Search 我的代码: $Text = WinGetText("[ACTIVE]") Sleep(4000) $Value = StringSplit($Text, @CRLF) MsgBox(0, "Hello", $Value, 10) ;---1st message box Sleep

我需要从文本中提取数字信息

Ready

State: CTYG  Work Request #: 2880087 General

Job Address

Contact

Work Request Search
我的代码:

$Text = WinGetText("[ACTIVE]")
Sleep(4000)
$Value = StringSplit($Text, @CRLF)
MsgBox(0, "Hello", $Value, 10) ;---1st message box
Sleep(4000)

For $i = 1 To $Value[0]

    If StringRegExp($Value[$i], "[0-9][^:alpha:]") Then

        MsgBox(0, "Hello1", $Value[$i], 5) ;---2nd message box
        Sleep(200)
        $newWR = $Value[$i]
        MsgBox(0, "Hello2", $newWR, 10)
        ConsoleWrite($newWR) ;---3rd message box

    EndIf

Next

第一个
MsgBox()
不显示任何内容。第二次和第三次显示
状态:CTYG工作请求#:2880087常规
。但是我不需要整条线,我只想要
2880087

这个怎么样?这将删除除数字以外的所有内容

$str = "State: CTYG Work Request #: 2880087 General"
ConsoleWrite(StringRegExpReplace($str, '\D', '') & @CRLF)
…我只想要2880087

使用正则表达式的示例
状态:.+:(\d+)

#包括;StringRegExp()
#包括
全局常量$g_sText='Ready'&@CRLF&@CRLF_
&“状态:CTYG工作请求#:2880087概述”&@CRLF&@CRLF_
&“工作地址”&@CRLF&@CRLF_
&“联系人”&@CRLF&@CRLF_
&“工作请求搜索”
全局常量$g_sRegEx='状态:.+:(\d+)
全局常量$g_aResult=StringRegExp($g_sText,$g_sRegEx,$STR_REGEXPARRAYMATCH)
控制台写入($g_sText和@CRLF)
_阵列显示($g_aResult)

2880087
存储到
$g_aResult[0]

我已经能够像下面这样做:$Text=WinGetText(“[ACTIVE]”)sleep(40)$Value=StringMid($Text,38,8)这给了我号码2880087,但这只是硬编码编码,我想知道是否有办法在没有任何硬编码的情况下精确定位2880087的位置。您的第一个MsgBox没有显示任何内容,因为
$Value
是一个数组,而不是字符串。您应该改用
\u ArrayDisplay
#include <StringConstants.au3>; StringRegExp()
#include <Array.au3>

Global Const $g_sText   = 'Ready' & @CRLF & @CRLF _
                        & 'State: CTYG Work Request #: 2880087 General' & @CRLF & @CRLF _
                        & 'Job Address' & @CRLF & @CRLF _
                        & 'Contact' & @CRLF & @CRLF _
                        & 'Work Request Search'
Global Const $g_sRegEx  = 'State: .+ #: (\d+)'
Global Const $g_aResult = StringRegExp($g_sText, $g_sRegEx, $STR_REGEXPARRAYMATCH)

ConsoleWrite($g_sText & @CRLF)
_ArrayDisplay($g_aResult)