Backslashing the [ and ] in a regex

From: Date: Wed, 04 Feb 2004 19:06:38 +0000
Subject: Backslashing the [ and ] in a regex
Groups: php.general 
Request: Send a blank email to php-general+get-176837@lists.php.net to get a copy of this message
I am kind of stuck on a problem that I am hoping you can help with. I am working on an application where the user can input a regular expression into a text box on a web form. This regular expression will be put into a postgres database, then later into an XML file. My dilemma is that if a user backslashes characters like +, *, etc I use the line below to put an extra backslash on those before they go into the database: $rule = ereg_replace("\\\\[[:alpha:]+*/.|<>()$]", "\\\\0", $rule) ; But if the user backslashes either a left or right bracket ([ or ]), I am having difficulty getting that extra backslash into the string. I tried just adding the [ and ] characters to the line above between the <> and () characters, but that didn't work along with several other iterations of attempts to get it to work. Does anyone have any ideas? I am stuck. TIA! --Sam

« previous php.general (#176837) next »