明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 852|回复: 0

正则替换

[复制链接]
发表于 2017-8-16 10:32 | 显示全部楼层 |阅读模式
本帖最后由 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:替换后的字符串
;;;exampleBF-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 "attern" express)
  (setq s (vlax-invoke-method regex 'RePlace string newstr))
  (vlax-release-object RegEx)
  s
)
<以上内容出自《大海语录》不代表本人观点>欢迎加入通信管线设计技术交流群655280537,通信管线规划设计技术、资源交流群,CAD底图交换、付费教程免费获取、交流经验、互相学习,共同进步!



您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-26 17:15 , Processed in 0.363894 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表