使用正则表达式替换 - VBA [英] Using replace with regular expressions - VBA

查看:72
本文介绍了使用正则表达式替换 - VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想格式化文本.我的意思是这样的:我想改变这个:

I would like to format a text. I mean something like this: I'd like to transform this:

"something'text between apostrophes'text"

进入

"something 'text between apostrophes' text"

我想从两边添加空格,但保持 '' 中的字符串相同.我试着这样做:

I want to add spaces from both sides, but keep te string in '' the same. I tried to do it like this:

  Arkusz1.Cells(1, 1).Replace What:="'*'" Replacement:=" '*' "

但它的结果是:

"something '*' text"

Arkusz1.Cells(1,1) 包含我要替换的 string.是否有可能做到这一点?谢谢

Arkusz1.Cells(1,1) contains the string I want to replace. Is it possible to do this? Thanks

推荐答案

你可以试试这个正则表达式:

You can try this regex:

('[^']+')

并替换为:

" $1 "

正则表达式 101 演示

这篇关于使用正则表达式替换 - VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆