說明
i)^(?:\*spec\*)?\s*([^:]*)\s+:\s+!hello
我使用insenstitve標誌的情況下對這個表達式,其在AutoHotkey的應用爲i)
。
例
AutoHotkey的示例代碼
InputString := "*SPEC* TEST TEST : !hello"
RegexMatch(InputString, "i)^(?:\*spec\*)?\s*([^:]*)\s+:\s+!hello", Match)
strMessage := "InputString = '" . InputString . "'"
strMessage .= "`nName = '" . Match1 . "'"
MsgBox, % strMessage
AutoHotkey的輸出
---------------------------
DesktopAutomation.ahk
---------------------------
InputString = '*SPEC* TEST TEST : !hello'
Name = 'TEST TEST'
---------------------------
OK
---------------------------
現場演示
正則表達式例子:https://regex101.com/r/tP1uI5/1
示例文本
*SPEC* TEST TEST : !hello
樣品匹配
MATCH 1
1. [7-16] `TEST TEST`
說明
NODE EXPLANATION
----------------------------------------------------------------------
i) set case insensitive mode
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\* '*'
----------------------------------------------------------------------
spec 'spec'
----------------------------------------------------------------------
\* '*'
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[^:]* any character except: ':' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
!hello '!hello'
----------------------------------------------------------------------
如果要更換字符串與它的regEx部分,使用'regExReplace' – Blauhirn