What's the best way to escape user input for Regular Expressions in MySQL?

the barber shop

New Member
I'd like to take user input, denoted as $dangerous_string, and use it as part of a RegEx in a MySQL query.What's the best way to go about doing this? I want to use the user's string as a literal -- if it contains any characters that mean something in MySQL RegEx, those characters should not actually affect my Regular Expression.\[code\]$dangerous_string = $_GET["string"];//do something here$dangerous_string = what_goes_here($dangerous_string);$sql = "SELECT * FROM table WHERE search_column REGEX '[[:<:]]$dangerous_string'";//etc....\[/code\]
 
Back
Top