# Bug in Str.full\_split?

**URL:** <https://discuss.ocaml.org/t/bug-in-str-full-split/8254>\
**Category:** Community\
**Tags:** stdlib, str\
**Created:** [August 5, 2021, 1:12am UTC](https://discuss.ocaml.org/t/bug-in-str-full-split/8254 "2021-08-05T01:12:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [August 5, 2021, 1:12am UTC](https://discuss.ocaml.org/t/bug-in-str-full-split/8254/1 "2021-08-05T01:12:08Z")

</div>

Hello,

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

In utop:

```ocaml
#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:

```ocaml
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.

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [August 5, 2021, 2:06am UTC](https://discuss.ocaml.org/t/bug-in-str-full-split/8254/2 "2021-08-05T02:06:17Z")

</div>

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

```ocaml
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 `]`.

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [August 5, 2021, 2:47am UTC](https://discuss.ocaml.org/t/bug-in-str-full-split/8254/3 "2021-08-05T02:47:34Z")

</div>

Thanks! I did not try this one.
