How Many Parameters Allowed in VBA Regex .Replace Method?

Go To StackoverFlow.com

0

! I am working with the replace method of VBA Regex and am wondering how many parameters it can take? I've seen the msdn page that gives lots of different options, but I'm unsure about which to use. Here's the link to that page: MSDN Page: Regex.Replace Method

I would like to be able to use backreferences and other VBA Regex in the 'replace with' parameter, if possible.

I'm currently only able to do this, for example (a literal text replacement)

 RE6a = RE.Replace(strData, " ")

I would like to do this, for example:

 RE6a = RE.Replace(strData, \s)

or

 RE6a = RE.Replace(strData, \1 \3 \4)

How can I do this in VBA Regex?

Thanks for any help!

2012-04-05 20:08
by buck1112
Your link is for .NET Regex, not what you'd use in VBA - Jay 2012-04-05 20:14
You can't substitute other regex expressions in Replace - brettdj 2012-04-06 02:18
Do you have a particular example where your string literal or submatch replacement doesn't achieve what you need - brettdj 2012-04-06 02:33


3

VBA does not have regular expressions. To use them, you have to reference a regex library first.

If it happened so that you referenced the Microsort VBScript Regular Expressions library, then you'll find the answer in the documentation:

' Swap first pair of words.
MsgBox(ReplaceTest("(\S+)(\s+)(\S+)", "$3$2$1"))
2012-04-05 20:24
by GSerg
I had commented that this particular example swapped submatches rather than backreferences. But the process used above with submatches (ie the "$1" syntax) is the same to reference backreferencesbrettdj 2012-04-06 02:27
Ads