

Task

   match a string against a regular expression
   substitute part of a string using a regular expression


[indent=4]
/* Regular expressions, in Genie */
 
init
    var sentence = "This is a sample sentence."
    try
        var re = new Regex("s[ai]mple")
 
        if re.match(sentence)
            print "matched '%s' in '%s'", re.get_pattern(), sentence
 
        var offs = 0
        print("replace with 'different': %s",
            re.replace(sentence, sentence.length, offs, "different"))
 
    except err:RegexError
        print err.message