var str ="I am a string"if (str =~/string$/) {print"Ends with 'string'\n"}
Global matching:
var str =<<'EOF' x:Foo y:BarEOFwhile (var m = str=~/(\w+):(\S+)/g) { say "#{m[0]} -> #{m[1]}"}
Substitutions:
var str ="I am a string"# Substitute something mached by a regexstr.sub!(/ a /,' another ') # "I am a string" => "I am another string"# Remove something matched by a regexstr -=/ \Kanother /i# "I am another string" => "I am string"# Global subtitution with a blockstr = str.gsub(/(\w+)/, {|s1|'x'* s1.len}) # globaly replace any word with 'xxx'say str # prints: 'x xx xxxxxx'