Skip to content

Instantly share code, notes, and snippets.

@jasondavis
Forked from tmplinshi/RegExMatchAll.ahk
Created January 12, 2018 19:15
Show Gist options
  • Save jasondavis/1afb6d8ce890c9ff5eae7bd51291ec23 to your computer and use it in GitHub Desktop.
Save jasondavis/1afb6d8ce890c9ff5eae7bd51291ec23 to your computer and use it in GitHub Desktop.
/* 函数: RegExMatchAll
* 正则匹配所有结果,返回数组。
* 用法:
* RegExMatchAll(Haystack, NeedleRegEx, SubPat="")
* 参数:
* Haystack - 被搜索的字符
* NeedleRegEx - 正则表达式
* SubPat - (可选) 获取子匹配N,而非整个匹配
* 返回:
* 成功返回数组,失败返回空。
*/
RegExMatchAll(ByRef Haystack, NeedleRegEx, SubPat="") {
arr := [], startPos := 1
while ( pos := RegExMatch(Haystack, NeedleRegEx, match, startPos) ) {
arr.push(match%SubPat%)
startPos := pos + StrLen(match)
}
return arr.MaxIndex() ? arr : ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment