2017-10-12 193 views
1

我想格式化文本。我的意思是這樣的: 我想改變這個:使用替換正則表達式 - VBA

"something'text between apostrophes'text" 

"something 'text between apostrophes' text" 

我想從兩邊添加空格,但要'同TE字符串。 我試圖做這樣的:

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

但其結果是:

"something '*' text" 

Arkusz1.Cells(1,1)包含string我想要替換。是否有可能做到這一點? 感謝

回答

1

你可以試試這個正則表達式:

('[^']+') 

並以此取代:

" $1 " 

樣品來源

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