Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: The craziest RegExes you ever created

by peterdragon (Beadle)
on Jul 04, 2006 at 08:30 UTC ( [id://559113]=note: print w/replies, xml ) Need Help??


in reply to The craziest RegExes you ever created

I had to robustify a database layer that was talking to a DB that couldn't store a range of characters including single quote and other punctuation. Also some of the calling code, which I wasn't able to touch, would fail to escape quote characters properly.
Code snippets:
sub fix_dodgy_chars { my $s = shift; $s = '' unless defined $s; $s =~ s/[:;<>\[\]`{|}\000-\037£]/ /g; # replace dodgy chars with sp +ace $s =~ s/\'/\_/; # single quote translated to underscore $s; } sub Prepare { ... # map non-escaped embedded single or double quotes to underscore where + neither at end of line # nor followed by semicolon, comma, whitespace or rightbracket $sqlstring =~ s/([^\\\s\,\(])([\'\"])(?!($|[\;\,\s\)]))/$1_/g; # then examine quoted strings and replace characters that sql cannot h +andle, currently # : ; < > [ ] ` { | } & $sqlstring =~ s/\"([^\"]*)\"/'"'.fix_dodgy_chars($1).'"'/ge;} ... }
--
peterdragon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://559113]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-26 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found