1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

正規表記

Last updated at Posted at 2018-04-13

正規表現(regular expression)とは、文字列の集合を一つの文字列で表現する方法の一つである。
by wiki

> "string".class
=> String

> /regexp/.class
=> Regexp

##str.sub(pattern, replacement)

> str = "林さん、お元気ですか"
=> "林さん、お元気ですか"
> str.sub(/さん/, "様")
=> "林様、お元気ですか"

##str.gsub(pattern, replacement)

> str = "痛い、痛い、ドアに足をぶつけた!"
=> "痛い、痛い、ドアに足をぶつけた痛い!"

> str.gsub(/痛い/, "痛くない")
=> "痛くない、痛くない、ドアに足をぶつけた痛くない!"

Ruby 正規表現の使い方:
https://qiita.com/shizuma/items/4279104026964f1efca6
を参考にさせていただいてます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?