RegExp different behavior in .NET and VB script?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

As an example, in VbScript ".*\Rad.DAT" is considered a valid regular expression, but in VB7 and C# I'm getting following error message
parsing ".*\Rad.DAT" - Unrecognized escape sequence \R. Parameter name: .*\Rad.DAT
This is happening for any character that do not have an correspondent escape sequence.
".*\Aad.DAT" is okay because "\a" is an escape sequence

Here is a program sequence that uses VBScript library and consider the mentioned regular expression as a correct one
Dim regex As VBScript_RegExp_55.RegEx
regex = New VBScript_RegExp_55.RegEx
regex.Pattern = ".*\Rad.DAT
regex.IgnoreCase = Tru
regex.Global = Tru
Matches = regex.Execute(sToMatch
This sequence returns an error
TestRE = ".*\Rad.DAT
Dim reg As Rege
'reg = New Regex(TestRE, RegexOptions.IgnoreCase
reg = New Regex(TestRE, RegexOptions.CultureInvariant And RegexOptions.IgnoreCase
'reg = New Regex(TestRE
Dim m As System.Text.RegularExpressions.Matc
m = reg.Match(strToMatch
Thanks
GD
 
I don't think it's the regexp behaviour that's different, it's more likely
the string behaviour that is. I guess that '\' is not seen as an escape
character by vbscript strings , though it is one in C# strings.

GD said:
As an example, in VbScript ".*\Rad.DAT" is considered a valid regular
expression, but in VB7 and C# I'm getting following error message.
parsing ".*\Rad.DAT" - Unrecognized escape sequence \R. Parameter name: ..*\Rad.DAT.
This is happening for any character that do not have an correspondent escape sequence.
".*\Aad.DAT" is okay because "\a" is an escape sequence.

Here is a program sequence that uses VBScript library and consider the
mentioned regular expression as a correct one.
 
Back
Top