Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created March 17, 2013 17:56
Show Gist options
  • Select an option

  • Save chiragmongia/5182765 to your computer and use it in GitHub Desktop.

Select an option

Save chiragmongia/5182765 to your computer and use it in GitHub Desktop.
p "Enter the string"
line = gets.chomp
p "Enter pattern to be searched"
pattern = gets.chomp
p matchfound = line.gsub(/#{pattern}/,"(#{pattern})")
print "Number of occurences- "
p line.scan(/#{pattern}/).size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment