VBAScript does not support lookbehind. Neither, as far as I know, does it support replace callbacks, otherwise we could use the method in this question to "regex-match a pattern unless..." to do something like:
Dim myRegExp, replaced
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "^[^ /]* / |( / )"
replaced = myRegExp.Replace(SubjectString,
// some function that only replaces the match if Group 1 is set.
)
As far as I can see, this leaves us with a three-step solution:
- Replace the first one with something distinctive
- Replace the other ones
- Replace the first one again
1. Replacing the first one:
Search: ^([^ /]*) /
Replace: $1@@DISTINCTIVE@@
Some code:
Dim myRegExp, replaced
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "^([^ /]*) / "
replaced = myRegExp.Replace(SubjectString, "$1@@DISTINCTIVE@@")
2. Replacing the other ones:
Search: /
, Replace: ""
3. Restoring the first one:
Search: @@DISTINCTIVE@@
, Replace: /