splitn
is a CLI application that generates combinations of chars being a result of splitting strings provided explicite or randomly generated from regex patterns. It is made mainly for testing NLU applications, e.g. chatbots or tools for extracting structural data from text like duckling.
pipx install splitn
or
pip install splitn
$ splitn 486
486
48 6
4 86
4 8 6
$ splitn "\d{3"
427
4 27
42 7
4 2 7
Let's assume that file example.txt
contains following lines.
abc
\d{2}
$ splitn example.txt
abc
a bc
ab c
a b c
---
04
0 4
$ splitn abc -s -
abc
a-bc
ab-c
a-b-c
$ splitn "\d{2}" -t 2
59
5 9
35
3 5
$ splitn abc def --secondary-separator +++
abc
a bc
ab c
a b c
+++
def
d ef
de f
d e f
$ splitn "\d{2}" --as-string
\d{2}
\ d{2}
\d {2}
\d{ 2}
\d{2 }
\ d {2}
\ d{ 2}
\ d{2 }
\d { 2}
\d {2 }
\d{ 2 }
\ d { 2}
\ d {2 }
\ d{ 2 }
\d { 2 }
\ d { 2 }
This option can be used with or without positional arguments. When used without, it makes splitn generate random sequences based on given regular expressions. When used with operands, it narrows down generated sequences to those matching provided regular expressions.
$ splitn -p "\d \d .{2}"
8 1 Ua
$ splitn "\d{4}" -p "\d \d .*"
5 9 20
5 9 2 0