1
3

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.

正規表現の基本まとめ

Posted at

未来電子テクノロジーでインターンをしているyukako_nishimuraです。
今回は正規表現の基本について簡単にまとめました。

正規表現

文字を表す表現

記号 意味
. 任意の1文字
\d 数字1文字
\w 単語構成文字A-Za-z0-9
\s スペース、タブ、改行などのホワイトスペース
\D 数字以外
\W 単語構成文字A-Za-z0-9以外(句読点など)
\S スペース、タブ、改行などのホワイトスペース以外
\t タブ
\r キャリッジリターン(カーソルを文頭に戻す)
\b 単語の境界
\文字 特殊文字のエスケープ

文字の繰り返し表現

記号 意味
[1文字以上の文字] 括弧内に一致する文字があれば、一致
[^1文字以上の文字] 括弧内に一致する文字がなければ、一致
[文字-文字] アルファベット順、数字の昇順で、特定の文字から文字までの範囲を丸ごと指定できる。

文字の繰り返し表現

分かりやすいよう任意の1文字、または文字のグループをAとします。

記号 意味
A{数字} 指定した回数、文字を繰り返し
A{数字,数字} 指定した範囲内のいずれかの回数、文字を繰り返し
A+ 文字を1回以上繰り返し
A* 文字を0回以上繰り返し
A? 文字を0回または1回繰り返し

文字の位置を表す表現

記号 意味
^ Aは文頭
$ Aは文末

文字のグループ化

記号 意味
(文字列) 文字のグループを定義する。入れ子にもできる。

論理記号

|でORつまりまたはを表せる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?