Re: Needing replacing a backslash by a comma
- From: "Alex K. Angelopoulos" <aka(at)mvps.org>
- Date: Fri, 9 May 2008 14:48:43 -0400
Yeah, this is one that takes a bit of punishment to do since \ is an escape character in a regex and you have to do a pattern match. The following demo code works, and should work with anything of the form
\\xxxx\
where xxxx is one or more of any characters other than \.
data = "\\192.168.1.2\SYSVOL"
Set rx = new regexp
rx.Pattern = "^(\\\\[^\\]+)\\"
data = rx.Replace(data, "$1,")
WScript.Echo data
Here's what the pattern does.
The initial ^ anchors the pattern to the beginning of the line; if your text begins with spaces ever, you may need to remove that.
The \\\\ matches \\, since each literal \ needs to be escaped with a \. The [^\\]+ bit means "one or more of any character _except_ \". The surrounding () tells the regex engine that this is a submatch to capture. Since it's the first captured match, the regex engine will remember it as $1 ($0 is reserved for the entire match, captured or not).
Finally, the terminal \\ matches a single \.
In your example, the regex engine would capture \\192.168.1.2, and the replacement expression replaces the entire matched section - which includes the terminal \ - with the capture followed by a ,.
"Blosjos" <Blosjos@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:49EBAA04-1A7F-4D56-89A0-96071A0688BE@xxxxxxxxxxxxxxxx
Hello,.
I just need to know how to find the third backslash in a string like this:
\\192.168.1.2\SYSVOL
It is like it was really \\anything\anything
and then replace it by a comma so that the string can be like:
\\192.168.1.2,SYSVOL
I have been trying with regular expressions but unsuccessfully.
Any ideas?
Thank you!
- References:
- Needing replacing a backslash by a comma
- From: Blosjos
- Needing replacing a backslash by a comma
- Prev by Date: Re: Needing replacing a backslash by a comma
- Next by Date: Group lookup problem
- Previous by thread: Re: Needing replacing a backslash by a comma
- Next by thread: Re: Needing replacing a backslash by a comma
- Index(es):
Relevant Pages
|
|