LoginSignup
3
3

More than 5 years have passed since last update.

文字列の一部を正規表現で抜き出して変数代入

Last updated at Posted at 2012-10-27

MatchData#capturesが便利.

year, month = /(.+)-(.+)-.+/.match("2012-10-27").captures

この例だったらyear, month = *date.split('-')でもいいけど

3
3
2

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
3
3