LoginSignup
2
0

More than 3 years have passed since last update.

colorizeと正規表現

Last updated at Posted at 2020-12-31

ruby-2.7.1p83

colorize

colorizeを使うとターミナルで出力する文字に色をつけることができる。

例えば、

require 'colorize'

def assert_equal(expected, result)
  if expected == result
    puts 'true'.cyan
  else
    puts 'false'.magenta
  end
end

assert_equal(1, 1)

とするとtrueがシアン、falseがマゼンタの色になって表示される。

正規表現

Rubular(http://rubular.com)はRubyベースの正規表現エディタである。正規表現を書く際にテストとして試すことができる。

例えば、test string として

Hello world!

と入力し、regular expression(正規表現)の部分に

\s(.+)

などと入力すれば

world!

のみが抽出できる。

実際にプログラムに書く前にチェックができるのは便利だと思った。


  • source ~/grad_members_20f/members/o-michika/3-regular-expression.org
2
0
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
2
0