For testing, I am trying to change from the single line:
One Two Three
into three lines:
One
Two
Three
Here is the test script., with five test lines
So I guess the basic question is how do I pass "\n" to the VB for EVAL?VBSTART
Function ReplaceTest(patrn, replStr)
Dim regEx, str1 ' Create variables.
str1 = "One Two Three"
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Make case insensitive. Default=False
ReplaceTest = regEx.Replace(str1, replStr) ' Make replacement.
End Function
VBEND
//Test1: Just reverses two of the words. This is sample from MSDN library! Actual result is No Good.
VBEval>ReplaceTest("(\S+)(\s+)(\S+)","$3$2$1"),string2
MessageModal>First two words were reversed.%CRLF%"One Two Three" becomes %string2%.
//Test2: Uses normal "\n" for the return code. -FAILS
VBEval>ReplaceTest("(\S+)(\s+)(\S+)","$1\n$2\n$3"),string2
MessageModal>Three words were placed on separate lines.%CRLF%"One Two Three" becomes %string2%.
Test3: Uses variable Rtn for "\n". -FAILS
Let>Rtn=\n
VBEval>ReplaceTest("(\S+)(\s+)(\S+)","$1%Rtn%$2%Rtn%$3"),string2
MessageModal>Three words were placed on separate lines.%CRLF%"One Two Three" becomes %string2%.
//Test4: Uses "\x0a" vs. "\n" for the return code. -FAILS
VBEval>ReplaceTest("(\S+)(\s+)(\S+)","$1\x0a$2\x0a$3"),string2
MessageModal>Three words were placed on separate lines.%CRLF%"One Two Three" becomes %string2%.
Test5: Uses "%CRLF%" for the return code. -FAILS
VBEval>ReplaceTest("(\S+)(\s+)(\S+)","$1%CRLF%$2%CRLF%$3"),string2
MessageModal>Three words were placed on separate lines.%CRLF%"One Two Three" becomes %string2%.
My actual RegEx is much more complex, requiring multiple instances of "\n" in the replacement string.
================================
I do have a second question about why the sample word reversals do no work. After doing some digging, I am thinking that I need to be using the Exec method in order to properly pick up the submatche collection values?
Why does the sample of $3$2$1 give Two One Three vs. Three Two One?
I am not used to the VB syntax for RegEx. Sample uses $1, $2, and refers to Jscript, I am used to \1, \2, etc. but see no reference to it in MSDN library. What am I missing here?