本帖最后由 Love-Lisp 于 2013-8-6 13:52 编辑
参看如下函数就知道如何得到位置了 - ;参数 string = 字串
- ;; Express = 正则表达式
- ;; key = 字母 i I m M g G的组合字串
- ;; i/I = 忽略大小写 m/M = 多行搜索 g/G = 全文搜索
- ;;测试 (RegExSearch "晓东CAD" "CA" "g") 返回 ((2 2 "CA"))
- (defun RegExSearch (STRING EXPRESS KEY / REGEX S POS LEN STR L)
- (setq RegEx (vlax-create-object "Vbscript.RegExp"))
- (if (and key (WCMATCH key "*g*,*G*"))
- (vlax-put-property regex "Global" 1)
- (vlax-put-property regex "Global" 0)
- )
- (if (and key (WCMATCH key "*i*,*I*"))
- (vlax-put-property regex "IgnoreCase" 1)
- (vlax-put-property regex "IgnoreCase" 0)
- )
- (if (and key (WCMATCH key "*m*,*M*"))
- (vlax-put-property regex "Multiline" 1)
- (vlax-put-property regex "Multiline" 0)
- )
- (vlax-put-property regex "Pattern" ExPress)
- (setq s (vlax-invoke regex 'Execute string))
- (vlax-for o s
- (setq pos (vlax-get-property o "FirstIndex")
- len (vlax-get-property o "Length")
- str (vlax-get-property o "value")
- )
- (setq l (cons (list pos len str) l))
- (princ (strcat "\n文字位置 = "
- (itoa pos)
- " 文字长度 = "
- (itoa len)
- " 值 = \""
- str
- "\""
- )
- )
- )
- (vlax-release-object RegEx)
- (reverse l)
- )
|