RosettaCodeData/Task/Regular-expressions/Zkl/regular-expressions-1.zkl
2023-07-01 13:44:08 -04:00

11 lines
466 B
Text

var re=RegExp(".*string$");
re.matches("I am a string") //-->True
var s="I am a string thing"
re=RegExp("(string)") // () means group, ie if you see it, save it
re.search(s,True) //-->True, .search(x,True) means search for a match, ie don't need .*
p,n:=re.matched[0] //.matched-->L(L(7,6),"string")
String(s[0,p],"FOO",s[p+n,*]) //-->"I am a FOO thing"
re.search(s,True); // using .matched clears it
m:=re.matched[1];
s.replace(m,"FOO"); // -->"I am a FOO thing"