Re: Character Escapes Don't Work in VB Regex Replace?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 02/25/04


Date: Wed, 25 Feb 2004 08:02:18 -0600

Chris,
As Brian suggested:

VB.NET just does not support C# escape sequences, nor does VB.NET define its
own escape sequences!

The "\n" is only supported in regular expressions and replacement patterns,
not the replace string according to the Character Escapes section of Regular
Expression Language Elements:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconRegularExpressionsLanguageElements.asp

This is not a VB.NET problem per se, C# & every other .NET language will
have the same problem, as the RegEx class itself is defining this behavior.
(Read as I hope your rant is against the RegEx class and not VB.NET! ;-))

Unfortunately I do not know of a predefined routine that will replace the C#
escape sequences with their respective characters. If you build one, I would
recommend using a StringBuilder in the implementation.

Hope this helps
Jay

"Chris Anderson" <anonymous@discussions.microsoft.com> wrote in message
news:7E5B4138-0CC6-4BA1-AAD1-F4DAB8753766@microsoft.com...
> I guess I should have pointed that out in the original posting...
>
> I could certainly do it like that or by a few other means in the code. But
the problem is that I'm loading replace expressions dynamically from a text
file and I need the ability (specifically) to allow Unicode characters such
as \u200e in the replace expression, and also the whole range of general
character escapes. I can't hard code those. I could come up with a little
parser to replace character escapes from the script before sending them to
the regex replace, but that's a pain. There's no reason that VB shouldn't
support this. The regex engine is part of the .net framework and should
conform to common functionality, as far as I'm concerned. Anyway, regardless
of the fact that VB doesn't generally support escape characters doesn't mean
that they shouldn't work in regex. Afterall, $1 means nothing special in VB,
but does in a regex replace string.
>
> Now I'm just ranting... Point being, I need to do this the way it should
work. I'm hoping there's either some sort of update available or some crazy
secrect syntax such as $#\\u002e to do what I need.
>
> Thanks.



Relevant Pages

  • RfD: Escaped Strings S" (v6.3)
    ... Escape character is case sensitive, ... the S" string can only contain printable characters, ... impact of char in the file word sets. ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: problems with opening files due to files path
    ... GUI or it is a console app. ... of what an escape character and escape sequence is. ... character) inside a string specially, it makes the character after the ...
    (comp.lang.python)
  • Re: Getting Starting in JavaScript et al
    ... To date I have had three epiphanies where I have suddenly "got" javascript and realized how utterly diffident my previous understanding of the subject had been. ... Identifying and understanding the types of values that javascript uses; that there are 5 primitive data types (boolean, number, string, null and the undefined type). ... tab would then contain the tab character, ... Javascript has escape sequences that start with a backslash, but there are a number of types. ...
    (comp.lang.javascript)