问题
Yes, I have searched (and found) many response similar to this, but none work for me. I have a lot of patterns to replace, most along these lines:
Find: ([aA])ttorney-at-law Replace: \1ttorney at law
I could create two ordinary find/replaces for each case, but I've got hundreds to do. Any help or direction would be much appreciated. I can do this in NPP, but the people I'm doing this for work in Word exclusively.
I've got other phrases where I'm adding hyphens or, e.g., changing ([bB])ook store (two words) to \1ookstore (one word, retaining original case).
I got this suggestion elsewhere, and just plugged my patterns in, but it doesn't do anything:
Sub SearchReplace()
Dim regEx As Object
Dim qtext As String
Dim html_input As String
' set up regex
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "\(\[aA\]\)ttorney-at-law"
regEx.Global = True
' input and replacement text
qtext = "\(\[aA\]\)ttorney-at-law"
html_input = "\1ttorney at law"
' do replace
qtext = regEx.Replace(qtext, html_input)
End Sub
Thank you!
来源:https://stackoverflow.com/questions/50274476/using-vba-regular-expressions-to-find-replace-in-word