Bug in Str.full_split?

Hello,

I am not sure why this is not working. Is it a bug?

In utop:

#require "str";;
Str.(full_split (regexp "[\\]\\[]") "[toto]titi[tata]");;
- : Str.split_result list = [Str.Text "[toto]titi[tata]"]
Str.(full_split (regexp "[\\[\\]]") "[toto]titi[tata]");;
- : Str.split_result list = [Str.Text "[toto]titi[tata]"]

On the contrary, this one does what I expect:

Str.(full_split (regexp "[}{]") "{toto}titi{tata}");;
- : Str.split_result list = [Str.Delim "{"; Str.Text "toto"; Str.Delim "}"; Str.Text "titi"; Str.Delim "{"; Str.Text "tata"; Str.Delim "}"]

So, I start to suspect that there is incorrect handling by Str of ‘[’ and ‘]’ in character sets.

Regards,
F.

In order to have a character class whose members are [ and ], I think the correct syntax is [][]:

utop # Str.(full_split (regexp "[][]") "[toto]titi[tata]");;
- : Str.split_result list =
[Str.Delim "["; Str.Text "toto"; Str.Delim "]"; Str.Text "titi"; Str.Delim "[";
 Str.Text "tata"; Str.Delim "]"]

No regexp metacharacters are recognized in character classes except for ^, and -, so the escape sequence is not recognized and the regexp is interpreted as "a character class whose only element is \, followed by the regexp-escaped character [, followed by the plain character ].

2 Likes

Thanks! I did not try this one.