[erlang-questions] split

Andreas Schultz <>
Fri Feb 14 10:53:34 CET 2014


Hi,

----- Original Message -----
> I'm sitting here feeling very stupid, can anybody explain to me in terms that
> a child of five could understand what's going on here:

REGEX are supposed to make you feel stupid all the time ;-)

> Problem: I want to split a string on repeated occurrences of the string
> "abc"
> 
> so split("123abcabc456") should return [<<"123">>,<<"456">>]
> 
> So I thought I could use re for this:
> 
> > re:split("123abcabc456", "(abc)+").
> [<<"123">>,<<"abc">>,<<"456">>]

Had to try a few things, but this works:

> re:split("123abcabcabc456", "(?:abc)+").           
[<<"123">>,<<"456">>]

This also works:

>  re:split("123abcabcabc456", "(abc)+",[no_auto_capture]).
[<<"123">>,<<"456">>]

> The manual page says the matching split string is not included in the
> output - at least that what it appear to me to say.
> 
> How in the name of the great blue-eyed slimy thing that hides under stones
> can I get rid of the additional <<"abc">> - this is totally not obvious to
> me.
> 
> try again:
> 
> > re:split("123abcabcabc456", "abc",[notempty]).
> [<<"123">>,<<>>,<<>>,<<"456">>]
> 
> 
> I was under the vague impression that <<>> *was* and empty string

[notempty] is not referring to returned string, but only to match.

> I knew I hated regular expressions, can't they be outlawed?

No, I like them ;-)

> /Joe

Andreas

-- 
-- 
Dipl. Inform.
Andreas Schultz



More information about the erlang-questions mailing list