For Programmers: Free Programming Magazines  


Home > Archive > Tcl > June 2007 > Re: Need a regex to escape all escapable characters in a string









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Need a regex to escape all escapable characters in a string
Mel

2007-06-27, 4:22 am

On Jun 25, 8:20 pm, TronyQ <jason.t.gen...@gmail.com> wrote:
> On Jun 25, 2:37 pm,Mel<MelHer...@gmail.com> wrote:
>
>
>
>
>
> Try:
>
> regsub -all {(\[\]\}\{\;\"'])} $string {\\\1} newstring
>
> There may be a way to not have to escape everything in the pattern but
> this seems to work...


When I try:

set string {A ' s " and { } BBBBs}
regsub -all {(\[\]\}\{\;\"'])} $string {\\\1} newstring
puts $newstring

I GET:[color=darkred]

am I doing something wrong with your regsub. There dont seem to be any
substitution done !!!

thanks for your help

Bryan Oakley

2007-06-27, 4:22 am

Mel wrote:
> On Jun 25, 8:20 pm, TronyQ <jason.t.gen...@gmail.com> wrote:
>
> When I try:
>
> set string {A ' s " and { } BBBBs}
> regsub -all {(\[\]\}\{\;\"'])} $string {\\\1} newstring
> puts $newstring
>
> I GET:
>
> am I doing something wrong with your regsub. There dont seem to be any
> substitution done !!!
>
> thanks for your help
>


You are missing a leading '['. Try this:

regsub -all {([\[\]\}\{\;\"'])} $string {\\\1} newstring


--
Bryan Oakley
http://www.tclscripting.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com