RosettaCodeData/Task/Regular-expressions/Sather/regular-expressions.sa

23 lines
682 B
Plaintext

class MAIN is
-- we need to implement the substitution
regex_subst(re:REGEXP, s, sb:STR):STR is
from, to:INT;
re.match(s, out from, out to);
if from = -1 then return s; end;
return s.head(from) + sb + s.tail(s.size - to);
end;
main is
s ::= "I am a string";
re ::= REGEXP::regexp("string$", true);
if re.match(s) then
#OUT + "'" + s + "'" + " ends with 'string'\n";
end;
if ~REGEXP::regexp("^You", false).match(s) then
#OUT + "'" + s + "'" + " does not begin with 'You'\n";
end;
#OUT + regex_subst(re, s, "integer") + "\n";
#OUT + regex_subst(REGEXP::regexp("am +a +st", true), s, "get the ") + "\n";
end;
end;