jpg102329 发表于 2017-8-16 10:32:25

正则替换

本帖最后由 jpg102329 于 2017-8-21 08:13 编辑

;正则替换
;【掌门】落魄山人<vicwjb@qq.com> 14:56:21
;;;name:BF-RegExp-RePlace
;;;desc:正则表达式替换字串
;;;arg:string:被替换字符串
;;;arg:newstr:替换的字串
;;;arg:express:正则匹配规则
;;;arg:key:字母 i I m M g G的组合字串,i/I = 忽略大小写 m/M = 多行搜索 g/G = 全文搜索
;;;return:替换后的字符串
;;;example:(BF-RegExp-RePlace "12345asd66" "bvd" "asd" "mg")
(defun BF-RegExp-RePlace (string newstr express key / regex s)
(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-method regex 'RePlace string newstr))
(vlax-release-object RegEx)
s
)
<以上内容出自《大海语录》不代表本人观点>欢迎加入通信管线设计技术交流群655280537,通信管线规划设计技术、资源交流群,CAD底图交换、付费教程免费获取、交流经验、互相学习,共同进步!



页: [1]
查看完整版本: 正则替换