![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||