Failed to get Erlang re work for multiline, please help!
> re:run("hello,\nworld", "o,.*w", [multiline]).
nomatch
> re:run("hello,\nworld", "o,.*w", [multiline, {newline, lf}]).
nomatch
> {ok, MP} = re:compile("o,.*w", [multiline]).
{ok,{re_pattern,0,0,
<<69,82,67,80,55,0,0,0,2,0,0,0,7,0,0,0,0,0,0,0,111,0,
119,...>>}}
> re:run("hello,\nworld", MP).
nomatch
> re:run("hello,\nworld", ",\nw").
{match,[{5,3}]}
The multiline option only tells the regex engine to treat ^ not only as the start of the string, but also as the start of a new line and it also tells the engine to treat $ not only as the end of the string, but as the end of a line.
Try this instead:
re:run("hello,\nworld", "o,.*w", [dotall])
The dotall option will tell the regex engine to also let line breaks be matched by the DOT meta character.
use the dotall option, i.e.
> re:run("hello,\nworld", "o,.*w", [dotall]).
{match,[{4,4}]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With