1. Computing

Discuss in my forum

Optional: ?

By , About.com Guide

The preceding element is optional. Either zero or one of the element may appear in the match text.

#!/usr/bin/env ruby

# Read a <a href="/od/glossary/g/string.htm">string</a> from the keyboard
# Print "success" if the string contains
# either the word "best" or "beast".
word = gets.chomp

if word =~ /bea?st/
  puts "success"
end
Top Related Searches chomp g string bea beast ruby lt
  1. About.com
  2. Computing
  3. Ruby
  4. Regular Expressions
  5. Optional: ?

©2013 About.com. All rights reserved.