[erlang-questions] Of regexes and REs, and other irritating things...

Mike Oxford moxford@REDACTED
Mon Aug 11 06:02:40 CEST 2014


I need to so some input sanitizing for use against MySQL.

"This isn't much of a \"test string\"; it'll have to do though."

Tried using the RE modules (yes, quad escaping crap) but the replacement
part for the back-references isn't working correctly.  Instead of getting
"\;" it's actually interpreting the backslash all the way down.  At least
it's not turtles all the way down.

So I went with a replacement of <92,"\\\\1"> thinking I'd get around it,
but it didn't work either.  Closest I got was "\\;" in the string which is
still incorrect.

So regexp is deprecated in favor of RE, but yet RE's pretty shitty for this
kind of thing.  I suppose I can just walk the list directly but then it's
incremental string-building.

Anyone have a "here dummy, you missed this NIF/built-in ... just use that"
to throw my way?

TIA!

122> re:replace("This isn't much of a \"test string\"; it'll have to do
though.",   "([';\"])",  <<92,"\\\\1">>,    [global, {return, binary}]).
<<"This isn\\'t much of a \\\"test string\\\"\\; it\\'ll have to do
though.">>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140810/b4d1e706/attachment.htm>


More information about the erlang-questions mailing list