[erlang-questions] escaping values for re:replace

Hynek Vychodil hynek@REDACTED
Tue Jul 27 23:54:53 CEST 2010


Usual perlish idiom is to escape all non alphanumeric characters. I
think that use of re module for escaping is little bit overkill. I
would write:

escape([]) -> [];
escape([H|T]) when H>=$0, H=<$9; H>=$a, H=<$z; H>=$A, H=<$Z -> [H|escape(T)];
escape([H|T]) -> [$\\, H|escape(T)].

This should be way how quotemeta works in Perl but only for latin1.

On Tue, Jul 27, 2010 at 10:53 PM, Wes James <comptekki@REDACTED> wrote:
> I created a function:
>
> escape(S) ->
>        S2=re:replace(S, "\\*", "\\\\*", [{return,list}, global]),
>        S3=re:replace(S2, "\\[", "\\\\[", [{return,list}, global]),
>        S4=re:replace(S3, "\\(", "\\\\(", [{return,list}, global]),
>        re:replace(S4, "\\)", "\\\\)", [{return,list}, global]).
>
> to escape the values I know. Is there a more erlang way to do this?
> I'm trying to replace all *, [, (, ) with the escaped values.
>
> thx,
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com


More information about the erlang-questions mailing list