问题
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
回答1:
You can try this regex:
('[^']+')
and replace by this:
" $1 "
Sample Source
Dim Regex As System.Text.RegularExpressions.Regex
Dim SubjectString As String = "something 'text between apostrophes' text"
Dim ResultString As String = Regex.Replace(SubjectString, "('[^']+')", " $1 ")
Console.WriteLine(ResultString)
Regex 101 Demo
来源:https://stackoverflow.com/questions/46702510/using-replace-with-regular-expressions-vba