tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
22
Task/Regular-expressions/Sather/regular-expressions.sa
Normal file
22
Task/Regular-expressions/Sather/regular-expressions.sa
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue