LoginSignup
20
20

More than 5 years have passed since last update.

Ruby1.9でひらがなやカタカナにマッチする正規表現

Last updated at Posted at 2012-04-11

1.9からは鬼車が採用されているので\{hiragana}などが使用できる。
「ー」やスペースはマッチしないので必要に応じて加える

ruby-1.9.2-p290 :025 > /^[\p{hiragana}ー-]+$/ =~ "ひらがな"
 => 0 
ruby-1.9.2-p290 :026 > /^[\p{katakana}ー-]+$/ =~ "カタカナー"
 => 0 

(返り値はマッチしたオフセットなので0)

20
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20