[erlang-questions] Problems with re:replace/4
Paul Burt
paul.burt@REDACTED
Fri Jul 22 09:56:03 CEST 2011
Sadly not, no. I tried that.
The replacement string simply returns the literal string "\k<mention>"
or "\\k<mention>" no matter how many backslashes I put in!
Cheers,
Paul
On 22 July 2011 08:51, Antoine Koener <antoine.koener@REDACTED> wrote:
> Whenever you deal with re module and the \ character, try \\ instead.
>
> There's 2 levels of filtering.
>
> Maybe this will help :))
>
>
>
> On 22 juil. 2011, at 09:39, Paul Burt <paul.burt@REDACTED> wrote:
>
>> Hi,
>>
>> I'm a newcomer to Erlang and am interested in writing some helper
>> functions to parse and manipulate responses from the Twitter API for
>> use in a web application.
>>
>> What I would like to do is replace "@mention" and "#hashtag" with HTML
>> markup as follows:
>>
>> @mention --> <a href="http://twitter.com/mention">@mention</a>
>> #hashtag --> <a href="http://search.twitter.com/search?tag=hashtag">#hashtag</a>
>>
>> In other words transform Twitter @mentions and #hashtags into clickable links.
>>
>> I have the basic structure of a function (tweetify/1) to do this
>> below. The ???? represent where I'm running into trouble:
>>
>> tweetify(Input) ->
>> Replacements = [
>> {"@(?<mention>\\w+)", "<a href=\"http://twitter.com/????\">&</a>"},
>> {"#(?<hashtag>\\w+)", "<a
>> href=\"http://search.twitter.com/search?tag=????\">&</a>"}
>> ],
>> lists:foldl(fun({RE, Replacement}, Tweet) ->
>> re:replace(Tweet, RE, Replacement, [global,
>> {return, binary}])
>> end, Input, Replacements).
>>
>> Whilst I understand that the token "&" will insert _everything_
>> matched by the regular expression (i.e. @mention and #hashtag
>> respectively), how do I use the named tags in the replacement string?
>> In other words, how do I get hold of \k<mention> and \k<hashtag> in
>> the PCRE idiom and use them in the replacement string?
>>
>> Thanks in advance for any assistance/pointers.
>>
>> -Paul
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list