[erlang-questions] escaping chars in re:replace

Wes James comptekki@REDACTED
Wed Jul 28 00:00:44 CEST 2010


What I'm doing is providing a search for site on book titles.  There
are *, [, (, ? chars in the data and I'm putting bold html around the
search text.  <b>search text</b>

I'm using re:replace on the the database return value.

Say a person types in "(b)", then on the page output this needs to be
changed to <b>(b)</b>.

Is there a better way to get the <b> around text with erlang other
than the re:replace?

thx,

-wes

On Tue, Jul 27, 2010 at 3:43 PM, Fred Hebert <mononcqc@REDACTED> wrote:
> There are many characters to escape:  ()[]{}\|*.+?:!$^<>= to name those I
> can think of.
>
> You have to be careful when accepting user-submitted regular expressions,
> because it's possible to find pathological cases that will take a long time
> to be ran. As far as I know, Erlang's re module is implemented as C code,
> which could potentially lock your node (if anyone can confirm/deny).
> It's generally a bad idea to run user-submitted regular expressions
> server-side.
> On Tue, Jul 27, 2010 at 4:40 PM, Wes James <comptekki@REDACTED> wrote:
>>
>> I'm replacing some values in some data.  It looks like when using
>>
>> re:replace here:
>>
>> http://www.erlang.org/doc/man/re.html
>>
>> the RE parameter needs to have the chars *, [, (,) escaped to be used.
>>
>> For example:
>>
>> re:replace("this*", "*", "!", [{return,list}, global, caseless])
>>
>> will error out with a bad argument error.  But this will work:
>>
>> re:replace("this*", "\\*", "!", [{return,list}, global, caseless])
>>
>>
>> What other chars should I be looking for that need to be escaped?  The
>> RE value comes in as a variable, so I will need to change any of these
>> chars to escaped before using it in re:replace.
>>
>> thx,
>>
>> -wes
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>
>


More information about the erlang-questions mailing list