[erlang-questions] Of regexes and REs, and other irritating things...
Per Hedeland
per@REDACTED
Mon Aug 11 09:03:29 CEST 2014
>Mike Oxford <moxford@REDACTED> wrote:
>
>I need to so some input sanitizing for use against MySQL.
Well, you're not saying exactly what you want to achieve, so it's a bit
difficult to comment, but...
>122> re:replace("This isn't much of a \"test string\"; it'll have to do
>though.", "([';\"])", <<92,"\\\\1">>, [global, {return, binary}]).
... it seems that you want to \-escape all occurences of ', ;, and "...
><<"This isn\\'t much of a \\\"test string\\\"\\; it\\'ll have to do
>though.">>
... and it seems that you succeeded.
>So I went with a replacement of <92,"\\\\1"> thinking I'd get around it,
You can use "\\\\\\1" instead with same result - not saying it is any
more readable:-), but avoids throwing in an ascii code and is actually a
little shorter...
>but it didn't work either. Closest I got was "\\;" in the string which is
>still incorrect.
I believe you are just confused by the "string rendering" - backslashes
must also be backslash-escaped in the "string form", there is only one
of them actually in there. Try this:
1> [97,92,59,98].
"a\\;b"
--Per Hedeland
More information about the erlang-questions
mailing list