LoginSignup
0
1

More than 1 year has passed since last update.

はじめに

移植やってます。

raw文字列 (Python)

r = r'R'
print(type(r))
print(r)
print(r == 'R')

<class 'str'>
R   
True

pythonの正規表現でよくr''って出てきますが、単なるストリングでした。

inspecct (Ruby)

r = /R/
puts r.class
puts r
puts r == 'R'

puts r.inspect
puts r.inspect.class
puts r.inspect.gsub(/\//, '') == 'R'

Regexp
(?-mix:R)
false

/R/
String
true

Ruby/で囲まれた文字列はRegexpクラスですので、文字列と比較する場合変換する必要があります。

もしくは、いったん文字列で保管しておいて正規表現で使用する際にインスタンス化するかですね。

メモ

  • Python の raw文字列 を学習した
  • 百里を行く者は九十里を半ばとす
0
1
0

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
0
1