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

on 18 Jun'19 17:31 in utilitiesstring manipulationregex

some useful string operations which appear to be absent in sclang

1
2
3
4
5
6
7
8
9
// note: first install quark https://github.com/shimpe/scstringext

(
"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 479 chars (focus & ctrl+a+c to copy)
reception
comments