Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Replace special characters

Reply
 
Old 03-08-2009   #1 (permalink)
Gabriela


 
 

Replace special characters

Hi,
I am trying to write a function that receives strings from all unicode
characters - and replaces all special characters (!@#$%^&*()><?...)
with "-", but literals as is.
I've tried to use regular expression with all special chars on ASCII
table - but it still doesn't cover everything.
I cannot use a "whitelist" (literals that are allowed) instead of a
"blacklist" (special chars NOT allowed) - because I don't know the
letters of all languages I'd like to support (English, Latin, Chinese,
Arabic...).
Any ideas what I can do?
Thanks,
Gabi.

This is my "black list" regular expression code - but it does not
succeed always...

dim oreg_exp
set oreg_exp = new RegExp
'oreg_exp.Pattern = "[^a-z0-9]"
oreg_exp.Pattern = "([{}\(\)\^$&._%#!@=<>:;,~`'\’ \*\?\/\+\|\[\\\\]|
\]|\-)"
oreg_exp.IgnoreCase = true
oreg_exp.global = true
title = oreg_exp.replace (title,"-")
Set oreg_exp = Nothing

My System SpecsSystem Spec
Old 03-08-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: Replace special characters

You haven't explained precisely what you mean by "special characters", but
I'm guessing you mean anything that is not a word character and is not a
space. For that, try this regular expression:

oreg_exp.Pattern = "[^ \w]"

"Gabriela" <frohlinger@xxxxxx> wrote in message
news:c3a12250-0107-45b8-a580-1668ca7c7119@xxxxxx
Quote:

> Hi,
> I am trying to write a function that receives strings from all unicode
> characters - and replaces all special characters (!@#$%^&*()><?...)
> with "-", but literals as is.
> I've tried to use regular expression with all special chars on ASCII
> table - but it still doesn't cover everything.
> I cannot use a "whitelist" (literals that are allowed) instead of a
> "blacklist" (special chars NOT allowed) - because I don't know the
> letters of all languages I'd like to support (English, Latin, Chinese,
> Arabic...).
> Any ideas what I can do?
> Thanks,
> Gabi.
>
> This is my "black list" regular expression code - but it does not
> succeed always...
>
> dim oreg_exp
> set oreg_exp = new RegExp
> 'oreg_exp.Pattern = "[^a-z0-9]"
> oreg_exp.Pattern = "([{}\(\)\^$&._%#!@=<>:;,~`'\’ \*\?\/\+\|\[\\\\]|
> \]|\-)"
> oreg_exp.IgnoreCase = true
> oreg_exp.global = true
> title = oreg_exp.replace (title,"-")
> Set oreg_exp = Nothing
My System SpecsSystem Spec
Old 03-08-2009   #3 (permalink)
Paul Randall


 
 

Re: Replace special characters


"Gabriela" <frohlinger@xxxxxx> wrote in message
news:c3a12250-0107-45b8-a580-1668ca7c7119@xxxxxx
Hi,
I am trying to write a function that receives strings from all unicode
characters - and replaces all special characters (!@#$%^&*()><?...)
with "-", but literals as is.
I've tried to use regular expression with all special chars on ASCII
table - but it still doesn't cover everything.
I cannot use a "whitelist" (literals that are allowed) instead of a
"blacklist" (special chars NOT allowed) - because I don't know the
letters of all languages I'd like to support (English, Latin, Chinese,
Arabic...).
Any ideas what I can do?
Thanks,
Gabi.

This is my "black list" regular expression code - but it does not
succeed always...

dim oreg_exp
set oreg_exp = new RegExp
'oreg_exp.Pattern = "[^a-z0-9]"
oreg_exp.Pattern = "([{}\(\)\^$&._%#!@=<>:;,~`'\’ \*\?\/\+\|\[\\\\]|
\]|\-)"
oreg_exp.IgnoreCase = true
oreg_exp.global = true
title = oreg_exp.replace (title,"-")
Set oreg_exp = Nothing

I don't know much about Unicode, but I have played with it a little.
Perhaps you should try going to http://unicode.org/. It has a wealth of
info about Unicode and related issues. You might try its various site
searches for the string 'special character' to get a better handle on what
defines a 'special character', which might help lead you to an answer.

-Paul Randall


My System SpecsSystem Spec
Old 03-08-2009   #4 (permalink)
Gabriela


 
 

Re: Replace special characters

On Mar 8, 6:53*pm, "Alex K. Angelopoulos" <aka(at)mvps.org> wrote:
Quote:

> You haven't explained precisely what you mean by "special characters", but
> I'm guessing you mean anything that is not a word character and is not a
> space. For that, try this regular expression:
>
> oreg_exp.Pattern = "[^ \w]"
>
> "Gabriela" <frohlin...@xxxxxx> wrote in message
>
> news:c3a12250-0107-45b8-a580-1668ca7c7119@xxxxxx
>
Quote:

> > Hi,
> > I am trying to write a function that receives strings from all unicode
> > characters - and replaces all special characters (!@#$%^&*()><?...)
> > with "-", but literals as is.
> > I've tried to use regular expression with all special chars on ASCII
> > table - but it still doesn't cover everything.
> > I cannot use a "whitelist" (literals that are allowed) instead of a
> > "blacklist" (special chars NOT allowed) - because I don't know the
> > letters of all languages I'd like to support (English, Latin, Chinese,
> > Arabic...).
> > Any ideas what I can do?
> > Thanks,
> > Gabi.
>
Quote:

> > This is my "black list" regular expression code - but it does not
> > succeed always...
>
Quote:

> > dim oreg_exp
> > set oreg_exp = new RegExp
> > 'oreg_exp.Pattern = "[^a-z0-9]"
> > oreg_exp.Pattern = "([{}\(\)\^$&._%#!@=<>:;,~`'\’ \*\?\/\+\|\[\\\\]|
> > \]|\-)"
> > oreg_exp.IgnoreCase = true
> > oreg_exp.global = true
> > title = oreg_exp.replace (title,"-")
> > Set oreg_exp = Nothing
That's all I needed. the little "[^ \w]" - thanks a lot!!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Replace special characters with regular expression VB Script
Password with special characters Live Mail
Replace special characters in filenames - how? PowerShell
Special Characters - how? Vista General
How to run program with special characters PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46