Skip to content

Instantly share code, notes, and snippets.

@muhammadyana
Created June 8, 2017 07:30
Show Gist options
  • Save muhammadyana/20a091017750c9f6682e1fd280a2404a to your computer and use it in GitHub Desktop.
Save muhammadyana/20a091017750c9f6682e1fd280a2404a to your computer and use it in GitHub Desktop.
regular expression
#thursday-08-2017
#@41studio
#Muhammad Yana Mulyana
#regex in ruby
#Operator =~ membandingkan string yg sama dan menghitung jumlah regex
# p /cat/ =~ "Dog and cat"
# p /cat/ =~ " ! # cat"
puts /aa/.class
puts "Enter String want te show "
a = gets.chomp.to_s
puts "Enter word want to search"
search = gets.chomp.to_s
p "kata yg dicari #{search.class}"
b = /an/
p b.match(a).pre_match
p b.match(a)[0]
p b.match(a).post_match
puts /a/.match(a)
puts Regexp.new("all").match(a)
# p match(a)
def show_regexp(string, pattern)
tes = pattern.match(string)
if tes
"#{tes.pre_match} -> #{tes[0]} <- #{tes.post_match}"
else
"No match"
end
end
p show_regexp("Very Interisting", /er/)
an = "The moon is made of cheese"
p show_regexp(an, /mo??o/)k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment