0

Alright so I have been using Regex until now to take care of a little clean up in a directory file. The problem I am having now is that the code I would use replaces the whole pattern.

Function CorrectTH(r As String) As String
 With CreateObject("VBScript.RegExp")
    .Global = True
    .IgnoreCase = False
    .Pattern = "[0-9]+TH\b"
    CorrectTH = .Replace(r, "th")
 End With
End Function

If I come across something like

"9TH ave & Hill St"

my replace will give me back

"th ave & Hill St"

when obviously I want to keep any numbers before the th. In this instance I want to return

"9th ave & Hill St"

Any trick to just change some of the pattern?

SteveG
  • 69
  • 7
  • 1
    `.Pattern = "([0-9]+)TH\b"` and then `CorrectTH = .Replace(r, "$1th")` – Wiktor Stribiżew Aug 28 '17 at 19:48
  • It is also worth looking at [online documentation](https://msdn.microsoft.com/en-us/library/k9z80300.aspx). It's not great, but at least has an example that points in the right direction. – C Perkins Aug 28 '17 at 19:49

0 Answers0