Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using replace with regular expressions - VBA

Tags:

regex

format

vba

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

"something'text between apostrophes'text"

into

"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:=" '*' "

But its result is:

"something '*' text"

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

like image 842
Jack123321 Avatar asked Nov 18 '25 12:11

Jack123321


1 Answers

You can try this regex:

('[^']+')

and replace by this:

" $1 "

Regex 101 Demo

like image 90
Rizwan M.Tuman Avatar answered Nov 21 '25 03:11

Rizwan M.Tuman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!