Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Substitute "\\" with "\\\\"

Quote Reply
Substitute "\\" with "\\\\"
Hi,


Last night I modified GT::CGI::unescape.
My try and error experiment with Links SQL...
Anyway,I have added a new substitution line:

$str =~ s/\\/\\\\/g;

after decode line:

$str =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;

Then I could successfully search any character that has "\\" in it.
But worst thing is that newly added Categories and Links (if these characters originally have "\\" code ) are built with extra "\\",messed up character.

How can I limit substitution to only search strings ?

like;

1 Users input search string(s).
2 Check to see if there are any "\\" in search string(s)
3 If there are "\\"s, it is replaced to "\\\\[/url]" ,looking like this;

$search string(s) =~ s/\\/\\\\/g;

4 Then go back to normal search routine.
5 Get searched results

I need to do this anyhow. Any help would be very much appreciated.

Thanks
### Moto ###
Quote Reply
Re: [Moto] Substitute "\\" with "\\\\" In reply to
What is a "\\" messed up character?

Isn't that regex infact substituting \ with \\ ....it doesn't change \\ to \\\\ ....half those slashes are escaping or did you know that?
Quote Reply
Re: [Paul] Substitute "\\" with "\\\\" In reply to
Hi,

I was wrong. I have typed too many "\'s".Frown

I changed my question as follows;
1 Users input search string(s).
2 Check to see if there are any "\" in search string(s)
3 If there are "\"s, it is replaced to "\\" ,looking like this;



$search string(s) =~ s/\\/\\\\/g;

4 Then go back to normal search routine.
5 Get searched results




Do I make myself understood ?

Thanks
### Moto ###
Quote Reply
Re: [Moto] Substitute "\\" with "\\\\" In reply to
Rather than all the escapes though, I would use something like;

$search string(s) =~ s,\,\\,g;

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Substitute "\\" with "\\\\" In reply to
Andy, using commas doesn't prevent you from having to escape in this situation Wink

Last edited by:

Paul: Oct 19, 2002, 10:07 AM
Quote Reply
Re: [Paul] Substitute "\\" with "\\\\" In reply to
Really?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Substitute "\\" with "\\\\" In reply to
Yes, really.

When you are using s/// you only escape forward slashes so they don't cause problems with the substitution delimeters, backslashes are irrelevant, however they must be escaped no matter what otherwise they are assumed to be an escape, so in order for them to be taken as a literal backslash you have to escape them.

Code:
\ = Escape or literal?
\* = Escape
\\ = Literal

Last edited by:

Paul: Oct 19, 2002, 10:26 AM
Quote Reply
Re: [Paul] Substitute "\\" with "\\\\" In reply to
Ooops...I see what you mean. I was thinking they were forward slashes Blush

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Substitute "\\" with "\\\\" In reply to
Hi forks,

Thanks for reply

If search string is a character set of "高性能".
I expect you to see "\" at the end of set with English encoded browsers.

This character set returns "No Matching Links" at search results.
Then I add another "\" making it look like "\\" like "高性能\",
I could search any character include "\" successfully.

I am not sure which modules and subs that I have to modify to achieve this.

Any help would be very very much appreciated.
### Moto ###

Last edited by:

Moto: Oct 19, 2002, 10:53 AM