Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: The craziest RegExes you ever created

by peterdragon (Beadle)
on Jul 04, 2006 at 08:30 UTC ( #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
Node Status?
node history
Node Type: note [id://559113]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2020-11-24 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?