本帖最后由 小菜123 于 2021-2-19 16:13 编辑
- ;|
- 功能 对字符串进行正则表达式匹配测试.
- 参数:
- pat = 正则表达式模式 ,对应vbs正则表达式的模式(expression)。说明: \\号要用\\\\替代.
- str = 字符串
- key = "i" "g" "m" , "i"不区分大小写(Ignorecase),"g"全局匹配(Global).
- "m"多行模式(Multiline),以上几个关键字可以组合使用,或用 "".
- 返回: 返回匹配的字符列表,或无一匹配返回nil
- |;
- (defun XD::String:RegExpS (pat str key / end keys matches x)
- (if (not *xxvbsexp)
- (setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
- )
- (vlax-put *xxvbsexp 'Pattern pat)
- (if (not key)
- (setq key "")
- )
- (setq key (strcase key))
- (setq keys '(("I" "IgnoreCase") ("G" "Global")
- ("M" "Multiline")
- )
- )
- (mapcar
- '(lambda (x)
- (if (wcmatch key (strcat "*" (car x) "*"))
- (vlax-put *xxvbsexp (read (cadr x)) 0)
- (vlax-put *xxvbsexp (read (cadr x)) -1)
- )
- )
- keys
- )
- (setq matches (vlax-invoke *xxvbsexp 'Execute str))
- (vlax-for x matches (setq end (cons (vla-get-value x) end)))
- (reverse end)
- )
|