[erlang-questions] re and newlines

Michael McDaniel <>
Sun Jan 10 21:13:30 CET 2010


On Sun, Jan 10, 2010 at 08:46:46PM +0100, 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.
>
 ________________________________________________________________

 from re module documentation, in the 'Newline sequences' section,
"
Outside a character class, by default, the escape sequence \\R matches any Unicode newline sequence.
"

 so perhaps the following would suffice ?

Eshell V5.7.4  (abort with ^G)
1> re:run("\rabc", "((\\R|.)+)(?=abc)").
{match,[{0,1},{0,1},{0,1}]}
2> re:run("\nabc", "((\\R|.)+)(?=abc)").
{match,[{0,1},{0,1},{0,1}]}
3> 


~Michael


More information about the erlang-questions mailing list