From: "Jan E." Date: 2012-04-14T05:22:31+09:00 Subject: Re: how to avoid escaping special chars after backslah in string Well, you cannot change the fact that backslashes are escape characters in string literals (unless you modified the Ruby Parser). You either have to double them or use the heredoc syntax mentioned by Vladimir. But does this situation even occur? I mean: In you final program, you probably won't type in the strings by hand but rather read them from a file or whatever. In this case, there's no problem at all. A backslash in a given string is a literal backslash. The escaping only happens with string literals written in Ruby. By the way: Your regex doesn't work anyway, because you're only checking for substrings. The "false alarm" has nothing to do with the double backslash: " ****imp" => this also matches, because it contains the substring "*img". Also the "|" are wrong in a character class. Why don't you use the regex we proposed in your other threads? Lucky Nl wrote in post #1056386: > " \\imp ".match(/ > [|@|#|$|+|{|}|'|"|?|<|>|*|-|!|%|^|&|:|;|\|=|.|~|`|^|\]|\[|'|\\|\/|\|]imp > /) > > when i am trying to match string around only one special char.it is > returning matching bcz the reason escaping slash . > > " *$imp ".match(/ > [|@|#|$|+|{|}|'|"|?|<|>|*|-|!|%|^|&|:|;|\|=|.|~|`|^|\]|\[|'|\\|\/|\|]imp > /) > > it will not match .this is returned as i expected > > In the firstcase also have 2 specialchars i want to expect that should > be work as like 2nd one > Vladimir wrote in post #1056383: >> On 04/13/2012 09:01 PM, Roger Pack wrote: >>> so what's your ideal syntax here? >>> >> if you need a avoid escaping completely you can use >> >> /heredoc/ >> >> myText =<> Please Det \ \t \n \r ach and return this coupon with your payment. >> Do not send cash or coins. >> >> Please write your name and account number on the check and >> make checks payable to: >> >> Acme Corporation >> >> Thank you for your business. >> DOC >> >> all characters will be saved as you print them without escaping -- Posted via http://www.ruby-forum.com/.