Ruby matching
From wikinotes
Documentation
regexp docs | https://docs.ruby-lang.org/en/master/Regexp.html |
regexp anchor docs | https://docs.ruby-lang.org/en/master/Regexp.html#class-Regexp-label-Anchors |
Basics
ruby's handling of regex looks similar to awk.
if 'ruby' =~ /^ru/
puts 'ruby starts with 'ru'
end
lang = 'ruby'
lang = %r'ruby' # regex string
lang = /ruby/ # regex string
ruby.sub(/by$/, 'BY') # replace first occurrence
ruby.gsub(/by$/, 'BY') # replace all occurrences