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 with regular expression

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


 
 

Replace special characters with regular expression

Hi,
I am trying to write a function that receives strings from all unicode
characters - and replaces all special characters (!@#$%^&*()><?...)
with "-", but leaves literals from all languages 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, German, French,
Chinese, Hebrew, Arabic...).
Any ideas what I can do?

This is my "black list" regular expression code - but it does not
succeed always...
There are still special characters with "pass through" the regexp:

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

I've been offered to use
oreg_exp.Pattern = "[^\w]" - but this doesn't support international
characters, only ASCII chars.

Thanks,
Gabi.

My System SpecsSystem Spec
Old 03-12-2009   #2 (permalink)
Paul Randall


 
 

Re: Replace special characters with regular expression


"Gabriela" <frohlinger@xxxxxx> wrote in message
news:545da651-19dc-48b3-b6f7-7b9cf05544b1@xxxxxx
Hi,
I am trying to write a function that receives strings from all unicode
characters - and replaces all special characters (!@#$%^&*()><?...)
with "-", but leaves literals from all languages 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, German, French,
Chinese, Hebrew, Arabic...).
Any ideas what I can do?

This is my "black list" regular expression code - but it does not
succeed always...
There are still special characters with "pass through" the regexp:

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

I've been offered to use
oreg_exp.Pattern = "[^\w]" - but this doesn't support international
characters, only ASCII chars.

Thanks,
Gabi.

I think you are saying that you can't make a white list because there are
just too many charsets/countrycodes/languages/Locales/LCIDs. And your
current blacklist is insufficient. Can you give us some specific examples
of special characters it doesn't catch -- the LCID and the Unicode code
point (number between 0 and 65535) so that we can research this a little.
If you use a script to get the code point, be sure to use the AscW function
rather than Asc. Asc can only return an 8-bit number execpt in a few
locales like Maltese.

-Paul Randall


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Regular Expression help C# .NET General
Replace special characters VB Script
Replace special characters in filenames - how? PowerShell
Help with a regular expression VB Script
regular expression help VB Script


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