Skip to content

Instantly share code, notes, and snippets.

@sudodo
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save sudodo/6b75f8bc26eaf75596e3 to your computer and use it in GitHub Desktop.

Select an option

Save sudodo/6b75f8bc26eaf75596e3 to your computer and use it in GitHub Desktop.
Remove symbol
# encoding: utf-8
def remove_symbol str
wide_symbol = "、 。 , . ・ : ; ? ! ゛ ゜ ´ ` ¨ ^  ̄ _ ヽ ヾ ゝ ゞ 〃 仝 々 〆 〇 ー ― ‐ / \ ~ ∥ | … ‥ ‘ ’ “ ” ( ) 〔 〕 [ ] { } 〈 〉 《 》 「 」 『 』 【 】 + - ± × ÷ = ≠ < > ≦ ≧ ∞ ∴ ♂ ♀ ° ′ ″ ℃ ¥ $ ¢ £ % # & * @ § ☆ ★ ○ ● ◎ ◇ ◆ □ ■ △ ▲ ▽ ▼ ※ 〒 → ← ↑ ↓ 〓"
str.gsub!(/[!-\/:-@\[-`{-~]*/,"") # => remove word consisting of only numeric or special chars like 123, `"$#
str.gsub!(/[#{wide_symbol}]/,"")
# str.gsub!(/[!。、*・]/,"")
str.gsub!(/\p{Symbol}/,"")
str
end
puts remove_symbol "@@@□a****(^・^)□"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment