LoginSignup
5
5

More than 5 years have passed since last update.

正規表現のメモ【超基本】

Last updated at Posted at 2016-06-11

以下をRubularで試してみてください。
RubularはRubyにおける正規表現のテストツールです。

^は入力文字の先頭を示す

$は入力文字の末尾を示す

*は直前の式を0回以上繰り返す = {0, }

+直前の式と1回以上一致したものを示す = {1, }

?は直前の式を0 or 1回示す = {0 ,1}

{n}は正確にn回一致する o{2}の場合、robは不一致、foodは一致する

{n , } = {n , *}

.は任意の1文字に一致する

hoge(?=n)はnの前にあるhogeを示す

hoge(?!n)はnの前にないhogeを示す

[xyz]の[ ]は文字セット指定する。各カッコの中にある文字列を示す

[^xyz]はxyz以外を示す

[a-z]はaからz

\d = [0-9]

\D = [^0-9]

\n = 改行

\s = スペース

\S = スペース以外の文字

\w = 単語 [A-Za-z0-9_]

\W = 単語以外  [^A-Za-z0-9_]
5
5
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
5
5