From: Vladimir Zhukov Date: 2012-04-14T05:32:06+09:00 Subject: Re: how to avoid escaping special chars after backslah in string Hm. I know you can escsape some characters with URI::encode URI::decode this methods for URLs but you can specify additional parameter - regexp which select what symbols you want encode. I'm not write custom regexp for thats. But maybe this can help. On 04/13/2012 11:22 PM, Jan E. wrote: > 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 >