«some missing string operations: split on regex; replace regex; between regex» by 56228375

on 18 Jun'19 23:31 in utilitiesstring manipulationregex

some useful string operations which appear to be absent in sclang

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// note: first install quark https://github.com/shimpe/scstringext
// using

Quarks.install("https://github.com/shimpe/scstringext");

// then you should be be able to run the following examples

(
"abcdefabcdef".splitRegex("bcd"); // yields [ "a", "efa", "ef" ]
"12-05-1984".replaceRegex("\\d+", "x"); // yields "x-x-x"
"12-05-1984".splitRegex("-"); // yields [ "12", "05", "1984" ]
"appple".replaceRegex("p+", "pp"); // yields "apple"
"<control> a=b <group> c=d <region> e=f <region> g=h <group> <region> i=j".betweenRegex("<group>", "<group>", 0, 1); // yields " c=d <region> e=f <region> g=h "
)
raw 612 chars (focus & ctrl+a+c to copy)
reception
comments