[erlang-questions] re and newlines

Sean Cribbs seancribbs@REDACTED
Sun Jan 10 21:04:44 CET 2010


In other PCRE implementations (Ruby, Perl), this is the "m" option on 
the regexp - that is, allowing '.' to match newlines. The corresponding 
option in the re module seems to be 'dotall'.

In Ruby:

 >> "\nabc" =~ /(.+)(?=abc)/
=> nil
 >> "\nabc" =~ /(.+)(?=abc)/m
=> 0
 >> "\rabc" =~ /(.+)(?=abc)/m
=> 0

In Erlang:

1> re:run("\nabc", "(.+)(?=abc)", []).
nomatch
2> re:run("\nabc", "(.+)(?=abc)", [dotall]).
{match,[{0,1},{0,1}]}
3> re:run("\rabc", "(.+)(?=abc)", [dotall]).
{match,[{0,1},{0,1}]}

Cheers,

Sean

On 1/10/10 2:46 PM, Zoltan Lajos Kis wrote:
> Hello all,
>
> Can I somehow convince re to treat _all_ kinds of newline characters 
> just like ordinary ones?
>
> 1> re:run("\rabc", "(.+)(?=abc)").
> {match,[{0,1},{0,1}]}
> 2> re:run("\nabc", "(.+)(?=abc)").
> nomatch
>
> I would like both of these (and all alike) to match. I see a {newline, 
> NLSpec} option, but it does
> not have an 'off' switch, does it?
>
> Regards,
> Zoltan.
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>



More information about the erlang-questions mailing list