From: Lucky Nl Date: 2012-04-15T18:42:42+09:00 Subject: Re: how to avoid escaping special chars after backslah in string Now am using regular expression " \*\imp ".match(/ [|@|#|$|+|{|}|'|"|?|<|>|*|-|!|%|^|&|:|;|\|=|.|~|`|^|\]|\[|'|\\|\/|\|]imp /) It is satisfying coniditions which i was expected .It will not return substring match except around specialchar.Am expecting to allow word only when it has single specialchar around that.But this is failing when string contains \ Jan E. wrote in post #1056404: > 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? -- Posted via http://www.ruby-forum.com/.