-
-
Save jasondavis/1afb6d8ce890c9ff5eae7bd51291ec23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 函数: 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