Ruby on Rails Regex Delete Array in string or word or in sentences.

14.06 Muhamad Akbar Bin Widayat 0 Comments

Official Ruby logo
Official Ruby logo (Photo credit: Wikipedia)
Hi all,

I will share to you to delete array in string using regex. Please follow me:
1. using regex str.match(/^.*KOPIKO.*$/) for example

  def self.delete_string_with_regex

    str = "KOPIKO RASA JERUK MANIS DAN MINT"

    arr = ["KOPIKOS", "JERUK", "COY"]

    arr.delete_if {|arr| str.match(/^.*#{arr}.*$/)}

  end
Enhanced by Zemanta

0 komentar:

terimakasih komentarnya