Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Regexp | casefold?

概要

Regexp#casefold?

詳細

正規表現が大文字小文字の判定をしないようにコンパイルされている時、 真を返却。

サンプルコード
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
/h.ge/i.casefold?
/h.ge/.casefold?
Regexp.compile("h.ge", Regexp::IGNORECASE).casefold?
Regexp.compile("h.ge").casefold?
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

/h.ge/i.casefold?                                    # => true
/h.ge/.casefold?                                     # => false
Regexp.compile("h.ge", Regexp::IGNORECASE).casefold? # => true
Regexp.compile("h.ge").casefold?                     # => false