Skip to content
UniKit

正規表現チートシート

文字クラス、量詞、グループと後方参照、アサーション、フラグ、よく使うパターン別に 129 個の正規表現構文をすばやく調べられます。各項目にはそのまま実行できる例と一致結果が付き、キーワード検索とワンクリックコピーに対応しています。

ブラウザ内で動作計算はすべてブラウザ内で行われ、データが端末の外に出ることはありません。

全 129 / 129 件

  • .Any single character, line breaks excluded by default文字クラス

    正規表現全体/a.c/g

    サンプルテキストabc a-c axc

    一致結果abca-caxc3 件一致

  • \dA digit 0-9, same as [0-9]文字クラス

    正規表現全体/\d+/g

    サンプルテキストOrder 42 has 7 items

    一致結果4272 件一致

  • \DAny character that is not a digit文字クラス

    正規表現全体/\D+/g

    サンプルテキスト123abc456

    一致結果abc1 件一致

  • \wWord character: letter, digit or underscore文字クラス

    正規表現全体/\w+/g

    サンプルテキストuser_name-42

    一致結果user_name422 件一致

  • \WAny character that is not a word character文字クラス

    正規表現全体/\W+/g

    サンプルテキストhello, world!

    一致結果, !2 件一致

  • \sWhitespace: space, tab, line break文字クラス

    正規表現全体/\s+/g

    サンプルテキストa b c

    一致結果 2 件一致

  • \SAny non-whitespace character文字クラス

    正規表現全体/\S+/g

    サンプルテキストa b c

    一致結果abc3 件一致

  • [abc]Any single character from the set文字クラス

    正規表現全体/[abc]+/g

    サンプルテキストcab dab

    一致結果cabab2 件一致

  • [^abc]Any character not in the set文字クラス

    正規表現全体/[^abc]+/g

    サンプルテキストabcxyz123

    一致結果xyz1231 件一致

  • [a-z]A character range文字クラス

    正規表現全体/[a-z]+/g

    サンプルテキストABC def GHI

    一致結果def1 件一致

  • [a-zA-Z0-9_]Several ranges combined文字クラス

    正規表現全体/[a-zA-Z0-9_]+/g

    サンプルテキストid_42 Name!

    一致結果id_42Name2 件一致

  • [^0-9]Everything except digits文字クラス

    正規表現全体/[^0-9]+/g

    サンプルテキストa1b2c3

    一致結果abc3 件一致

  • [\d]Character classes are allowed inside a set文字クラス

    正規表現全体/[\d]+/g

    サンプルテキストabc123def

    一致結果1231 件一致

  • [a\-z]An escaped hyphen means a literal hyphen文字クラス

    正規表現全体/[a\-z]+/g

    サンプルテキストa-z b

    一致結果a-z1 件一致

  • [\u4e00-\u9fff]The common CJK ideograph range文字クラス

    正規表現全体/[\u4e00-\u9fff]+/g

    サンプルテキスト中文 mingled 混排

    一致結果中文混排2 件一致

  • [\s\S]Any character including line breaks (unlike .)文字クラス

    正規表現全体/[\s\S]+/g

    サンプルテキストline1 line2

    一致結果line1 line21 件一致

  • [aeiou]A set of vowels文字クラス

    正規表現全体/[aeiou]+/g

    サンプルテキストbanana banana

    一致結果aaaaaa6 件一致

  • [\w-]Word characters or hyphens文字クラス

    正規表現全体/[\w-]+/g

    サンプルテキストkebab-case name

    一致結果kebab-casename2 件一致

  • *Zero or more of the preceding element量詞

    正規表現全体/ab*c/g

    サンプルテキストac abc abbbc

    一致結果acabcabbbc3 件一致

  • +One or more of the preceding element量詞

    正規表現全体/ab+c/g

    サンプルテキストac abc abbbc

    一致結果abcabbbc2 件一致

  • ?Zero or one of the preceding element量詞

    正規表現全体/colou?r/g

    サンプルテキストcolor colour

    一致結果colorcolour2 件一致

  • {n}Exactly n repetitions量詞

    正規表現全体/\d{3}/g

    サンプルテキスト12 345 6789

    一致結果3456782 件一致

  • {n,}At least n repetitions量詞

    正規表現全体/\d{2,}/g

    サンプルテキスト1 23 456

    一致結果234562 件一致

  • {n,m}Between n and m repetitions量詞

    正規表現全体/\d{2,4}/g

    サンプルテキスト1234567

    一致結果12345672 件一致

  • *?Lazy quantifier: as few repetitions as possible量詞

    正規表現全体/<.*?>/g

    サンプルテキスト<a><b>

    一致結果<a><b>2 件一致

  • +?Lazy quantifier with at least one repetition量詞

    正規表現全体/".+?"/g

    サンプルテキスト"a" "b"

    一致結果"a""b"2 件一致

  • ??Lazy optional: prefer zero repetitions量詞

    正規表現全体/https??/g

    サンプルテキストhttp https

    一致結果httphttp2 件一致

  • {n,m}?Lazy version of a range quantifier量詞

    正規表現全体/a{1,3}?/g

    サンプルテキストaaa

    一致結果aaa3 件一致

  • .*Greedy: match as far as possible量詞

    正規表現全体/a.*c/g

    サンプルテキストabc abc

    一致結果abc abc1 件一致

  • .*?Lazy: match as little as possible量詞

    正規表現全体/a.*?c/g

    サンプルテキストabc abc

    一致結果abcabc2 件一致

  • x{0,1}{0,1} is equivalent to ?量詞

    正規表現全体/x{0,1}y/g

    サンプルテキストxy y

    一致結果xyy2 件一致

  • (ab)+The quantifier applies to the whole group量詞

    正規表現全体/(ab)+/g

    サンプルテキストababab

    一致結果ababab1 件一致

  • (abc)Capturing group, referenced later as $1, $2グループと後方参照

    正規表現全体/(\w+)@(\w+)/g

    サンプルテキストalice@example bob@test

    一致結果alice@examplebob@test2 件一致

  • (?:abc)Groups without capturing (no numbering)グループと後方参照

    正規表現全体/(?:ab)+c/g

    サンプルテキストababc

    一致結果ababc1 件一致

  • (?<name>...)Named capture group for readabilityグループと後方参照

    正規表現全体/(?<year>\d{4})-(?<month>\d{2})/g

    サンプルテキスト2026-10

    一致結果2026-101 件一致

  • \k<name>Back-reference to a named groupグループと後方参照

    正規表現全体/(?<q>")\w+\k<q>/g

    サンプルテキスト"hi" "yo"

    一致結果"hi""yo"2 件一致

  • \1Back-reference to group 1 (repeated letters)グループと後方参照

    正規表現全体/(\w)\1/g

    サンプルテキストhello book

    一致結果lloo2 件一致

  • a|bAlternation: match either sideグループと後方参照

    正規表現全体/cat|dog/g

    サンプルテキストcat dog bird

    一致結果catdog2 件一致

  • (?:a|b)+Repeated alternation inside a groupグループと後方参照

    正規表現全体/(?:cat|dog)+/g

    サンプルテキストcatdogcat

    一致結果catdogcat1 件一致

  • ((a)(b))Nested groups, numbered by opening parenthesisグループと後方参照

    正規表現全体/((a)(b))/g

    サンプルテキストab

    一致結果ab1 件一致

  • $1Replacement reference to group 1 ("$2 $1" swaps)グループと後方参照

    正規表現全体/(\w+) (\w+)/g

    サンプルテキストhello world

    一致結果hello world1 件一致

  • $&In replacements, $& is the whole matchグループと後方参照

    正規表現全体/\d+/g

    サンプルテキストabc 123 def

    一致結果1231 件一致

  • $<name>Replacement reference to a named groupグループと後方参照

    正規表現全体/(?<word>\w+)/g

    サンプルテキストhello

    一致結果hello1 件一致

  • $$Outputs a literal dollar sign in replacementsグループと後方参照

    正規表現全体/a/g

    サンプルテキストa

    一致結果a1 件一致

  • ()An empty group, useful as a placeholderグループと後方参照

    正規表現全体/()b/g

    サンプルテキストab

    一致結果b1 件一致

  • ^Start of input (line start with the m flag)アサーション

    正規表現全体/^\w+/gm

    サンプルテキストhello world

    一致結果hello1 件一致

  • $End of inputアサーション

    正規表現全体/\w+$/g

    サンプルテキストhello world

    一致結果world1 件一致

  • \bWord boundary, avoids matching dog inside hotdogアサーション

    正規表現全体/\bdog\b/g

    サンプルテキストdog hotdog dog

    一致結果dogdog2 件一致

  • \BNon-word boundaryアサーション

    正規表現全体/\Bdog\B/g

    サンプルテキストhotdogish dog

    一致結果dog1 件一致

  • (?=x)Positive lookahead: the next characters must matchアサーション

    正規表現全体/\d+(?=元)/g

    サンプルテキスト价格 100元 与 50 件

    一致結果1001 件一致

  • (?!x)Negative lookahead: the next characters must not matchアサーション

    正規表現全体/\d+(?!元)/g

    サンプルテキスト100元 50 件

    一致結果10502 件一致

  • (?<=x)Positive lookbehind: the previous characters must matchアサーション

    正規表現全体/(?<=\$)\d+/g

    サンプルテキストprice $42 and 30

    一致結果421 件一致

  • (?<!x)Negative lookbehind: the previous characters must not matchアサーション

    正規表現全体/(?<!\$)\b\d+\b/g

    サンプルテキスト$42 and 30

    一致結果301 件一致

  • ^ + mWith the m flag ^ matches the start of every lineアサーション

    正規表現全体/^\w+/gm

    サンプルテキストone two three

    一致結果onetwothree3 件一致

  • $ + mWith the m flag $ matches the end of every lineアサーション

    正規表現全体/\w+$/gm

    サンプルテキストone two

    一致結果onetwo2 件一致

  • (?=.*\d)(?=.*[a-z])Combining lookaheads to express password rulesアサーション

    正規表現全体/^(?=.*\d)(?=.*[a-z]).{6,}$/g

    サンプルテキストabc123

    一致結果abc1231 件一致

  • (?!.*(.)\1)Rejecting repeated adjacent charactersアサーション

    正規表現全体/^(?!.*(.)\1).+$/g

    サンプルテキストabcdef

    一致結果abcdef1 件一致

  • (?<=\s)x(?=\s)Both assertions to target a word surrounded by spacesアサーション

    正規表現全体/(?<=\s)cat(?=\s)/g

    サンプルテキストa cat b

    一致結果cat1 件一致

  • ^(?!_)Asserting the input does not start with an underscoreアサーション

    正規表現全体/^(?!_)\w+$/g

    サンプルテキストname

    一致結果name1 件一致

  • (?<=\.)\w+$Extracting an extension without the dotアサーション

    正規表現全体/(?<=\.)\w+$/g

    サンプルテキストreport.pdf

    一致結果pdf1 件一致

  • (?=(\w+))Capturing inside a lookaheadアサーション

    正規表現全体/(?=(\d{2}))/g

    サンプルテキストab12cd34

    一致結果2 件一致

  • foo(?!bar)Matches foo when not followed by barアサーション

    正規表現全体/foo(?!bar)/g

    サンプルテキストfoo foobar

    一致結果foo1 件一致

  • gGlobal: find every match, not just the firstフラグ

    正規表現全体/a/g

    サンプルテキストbanana

    一致結果aaa3 件一致

  • iCase-insensitive matchingフラグ

    正規表現全体/hello/gi

    サンプルテキストHello HELLO hello

    一致結果HelloHELLOhello3 件一致

  • m^ and $ match at line boundariesフラグ

    正規表現全体/^b/gm

    サンプルテキストa b c

    一致結果b1 件一致

  • sLets . match line breaks tooフラグ

    正規表現全体/a.b/gs

    サンプルテキストa b

    一致結果a b1 件一致

  • uUnicode mode: code-point aware, enables \p{...}フラグ

    正規表現全体/^.$/gu

    サンプルテキスト👍

    一致結果👍1 件一致

  • ySticky: matches only at lastIndexフラグ

    正規表現全体/foo/gy

    サンプルテキストfoofoo

    一致結果foofoo2 件一致

  • dAdds match indices to the resultフラグ

    正規表現全体/\d+/gd

    サンプルテキストabc 123

    一致結果1231 件一致

  • [\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}Loose email: pick addresses out of proseよく使うパターン

    正規表現全体/[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}/g

    サンプルテキストcontact [email protected] now

    一致結果[email protected]1 件一致

  • ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$Strict email: validate the whole inputよく使うパターン

    正規表現全体/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/g

    サンプルテキスト[email protected]

    一致結果[email protected]1 件一致

  • ^https?:\/\/[\w.-]+(?::\d+)?(?:\/[^\s]*)?$http/https URL with optional port and pathよく使うパターン

    正規表現全体/^https?:\/\/[\w.-]+(?::\d+)?(?:\/[^\s]*)?$/g

    サンプルテキストhttps://example.com/docs?page=1

    一致結果https://example.com/docs?page=11 件一致

  • ^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$Domain name including subdomainsよく使うパターン

    正規表現全体/^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$/g

    サンプルテキストwww.example.com

    一致結果www.example.com1 件一致

  • \d{1,3}(?:\.\d{1,3}){3}Loose IPv4 matcherよく使うパターン

    正規表現全体/\d{1,3}(?:\.\d{1,3}){3}/g

    サンプルテキストip 192.168.1.1 ok

    一致結果192.168.1.11 件一致

  • (?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}Strict IPv4: every octet within 0-255よく使うパターン

    正規表現全体/(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}/g

    サンプルテキスト192.168.1.1 与 999.1.1.1

    一致結果192.168.1.199.1.1.12 件一致

  • (?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}Fully written IPv6 addressよく使うパターン

    正規表現全体/(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}/g

    サンプルテキスト2001:0db8:0000:0000:0000:ff00:0042:8329

    一致結果2001:0db8:0000:0000:0000:ff00:0042:83291 件一致

  • ^\d{4}-\d{2}-\d{2}$YYYY-MM-DD dateよく使うパターン

    正規表現全体/^\d{4}-\d{2}-\d{2}$/g

    サンプルテキスト2026-10-10

    一致結果2026-10-101 件一致

  • ^(\d{4})年(\d{1,2})月(\d{1,2})日$Chinese date with captured year, month, dayよく使うパターン

    正規表現全体/^(\d{4})年(\d{1,2})月(\d{1,2})日$/g

    サンプルテキスト2026年10月10日

    一致結果2026年10月10日1 件一致

  • ^([01]\d|2[0-3]):[0-5]\d$24-hour HH:MM timeよく使うパターン

    正規表現全体/^([01]\d|2[0-3]):[0-5]\d$/g

    サンプルテキスト09:30

    一致結果09:301 件一致

  • ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$ISO 8601 timestampよく使うパターン

    正規表現全体/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/g

    サンプルテキスト2026-10-10T08:30:00Z

    一致結果2026-10-10T08:30:00Z1 件一致

  • ^1[3-9]\d{9}$Mainland China mobile numberよく使うパターン

    正規表現全体/^1[3-9]\d{9}$/g

    サンプルテキスト13800138000

    一致結果138001380001 件一致

  • ^0\d{2,3}-\d{7,8}$Chinese landline with area codeよく使うパターン

    正規表現全体/^0\d{2,3}-\d{7,8}$/g

    サンプルテキスト010-12345678

    一致結果010-123456781 件一致

  • ^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]$Mainland China 18-digit ID numberよく使うパターン

    正規表現全体/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/g

    サンプルテキスト11010119900307721X

    一致結果11010119900307721X1 件一致

  • ^[1-9]\d{5}$Chinese 6-digit postal codeよく使うパターン

    正規表現全体/^[1-9]\d{5}$/g

    サンプルテキスト100000

    一致結果1000001 件一致

  • ^[\u4e00-\u9fa5][A-Z][A-Z0-9]{5}$Chinese licence plate (standard cars)よく使うパターン

    正規表現全体/^[\u4e00-\u9fa5][A-Z][A-Z0-9]{5}$/g

    サンプルテキスト京A12345

    一致結果京A123451 件一致

  • ^[\u4e00-\u9fa5]{2,4}$Chinese name of 2–4 charactersよく使うパターン

    正規表現全体/^[\u4e00-\u9fa5]{2,4}$/g

    サンプルテキスト张三丰

    一致結果张三丰1 件一致

  • ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$Strong password: 8+ chars with upper, lower, digit and symbolよく使うパターン

    正規表現全体/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$/g

    サンプルテキストAbc123!@#

    一致結果Abc123!@#1 件一致

  • ^[a-zA-Z][a-zA-Z0-9_]{2,15}$Username: starts with a letter, 3–16 charsよく使うパターン

    正規表現全体/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/g

    サンプルテキストalice_2026

    一致結果alice_20261 件一致

  • #(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\bHex colour valueよく使うパターン

    正規表現全体/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g

    サンプルテキストcolor: #fff and #A1B2C3

    一致結果#fff#A1B2C32 件一致

  • rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)rgb() / rgba() colourよく使うパターン

    正規表現全体/rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)/g

    サンプルテキストrgb(255, 0, 0) rgba(0, 0, 0, 0.5)

    一致結果rgb(255, 0, 0)rgba(0, 0, 0, 0.5)2 件一致

  • ^-?\d+$Integer, optionally negativeよく使うパターン

    正規表現全体/^-?\d+$/g

    サンプルテキスト-42

    一致結果-421 件一致

  • -?\d+\.\d+Decimal numberよく使うパターン

    正規表現全体/-?\d+\.\d+/g

    サンプルテキスト3.14 -0.5

    一致結果3.14-0.52 件一致

  • [+-]?\d+(?:\.\d+)?[eE][+-]?\d+Scientific notationよく使うパターン

    正規表現全体/[+-]?\d+(?:\.\d+)?[eE][+-]?\d+/g

    サンプルテキスト1.5e10 -3E-5

    一致結果1.5e10-3E-52 件一致

  • \b\d{1,3}(?:,\d{3})+\bNumber with thousands separatorsよく使うパターン

    正規表現全体/\b\d{1,3}(?:,\d{3})+\b/g

    サンプルテキストtotal 1,234,567 items

    一致結果1,234,5671 件一致

  • \d+\.\d{2}(?=\s|$)Money amount with two decimalsよく使うパターン

    正規表現全体/\d+\.\d{2}(?=\s|$)/g

    サンプルテキストprice 19.90 now

    一致結果19.901 件一致

  • \d+(?:\.\d+)?%Percentageよく使うパターン

    正規表現全体/\d+(?:\.\d+)?%/g

    サンプルテキスト增长 12.5% 与 30%

    一致結果12.5%30%2 件一致

  • 0[xX][0-9a-fA-F]+Hexadecimal literalよく使うパターン

    正規表現全体/0[xX][0-9a-fA-F]+/g

    サンプルテキスト0xFF 0X1a 10

    一致結果0xFF0X1a2 件一致

  • 0[bB][01]+Binary literalよく使うパターン

    正規表現全体/0[bB][01]+/g

    サンプルテキスト0b1010 0B11 5

    一致結果0b10100B112 件一致

  • 0[oO][0-7]+Octal literalよく使うパターン

    正規表現全体/0[oO][0-7]+/g

    サンプルテキスト0o755 8

    一致結果0o7551 件一致

  • ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$UUID v4よく使うパターン

    正規表現全体/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/g

    サンプルテキストf47ac10b-58cc-4372-a567-0e02b2c3d479

    一致結果f47ac10b-58cc-4372-a567-0e02b2c3d4791 件一致

  • ^[a-f0-9]{32}$MD5 hex digestよく使うパターン

    正規表現全体/^[a-f0-9]{32}$/g

    サンプルテキストd41d8cd98f00b204e9800998ecf8427e

    一致結果d41d8cd98f00b204e9800998ecf8427e1 件一致

  • ^[a-f0-9]{64}$SHA-256 hex digestよく使うパターン

    正規表現全体/^[a-f0-9]{64}$/g

    サンプルテキストba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

    一致結果ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad1 件一致

  • ^[A-Za-z0-9+/]+={0,2}$Base64 stringよく使うパターン

    正規表現全体/^[A-Za-z0-9+/]+={0,2}$/g

    サンプルテキストaGVsbG8=

    一致結果aGVsbG8=1 件一致

  • ^[\w-]+\.[\w-]+\.[\w-]+$JWT: three dot-separated segmentsよく使うパターン

    正規表現全体/^[\w-]+\.[\w-]+\.[\w-]+$/g

    サンプルテキストeyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc123

    一致結果eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc1231 件一致

  • ^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14})$Card number (simple Visa / MasterCard check)よく使うパターン

    正規表現全体/^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14})$/g

    サンプルテキスト4111111111111111

    一致結果41111111111111111 件一致

  • <\/?[a-zA-Z][\w-]*(?:\s[^<>]*)?>HTML tag including attributesよく使うパターン

    正規表現全体/<\/?[a-zA-Z][\w-]*(?:\s[^<>]*)?>/g

    サンプルテキスト<p class="x">text</p>

    一致結果<p class="x"></p>2 件一致

  • \[([^\]]+)\]\(([^)]+)\)Markdown link with captured text and URLよく使うパターン

    正規表現全体/\[([^\]]+)\]\(([^)]+)\)/g

    サンプルテキストsee [文档](https://example.com)

    一致結果[文档](https://example.com)1 件一致

  • "[^"\\]*(?:\\.[^"\\]*)*"Double-quoted string with escaped quotesよく使うパターン

    正規表現全体/"[^"\\]*(?:\\.[^"\\]*)*"/g

    サンプルテキスト"hello \"world\""

    一致結果"hello \"world\""1 件一致

  • ^([^,\n]+)(?:,([^,\n]+))*$Simple CSV row (no quoted fields)よく使うパターン

    正規表現全体/^([^,\n]+)(?:,([^,\n]+))*$/g

    サンプルテキストa,b,c

    一致結果a,b,c1 件一致

  • ^(?:\/[\w.-]+)+\/?$Absolute Unix pathよく使うパターン

    正規表現全体/^(?:\/[\w.-]+)+\/?$/g

    サンプルテキスト/usr/local/bin

    一致結果/usr/local/bin1 件一致

  • ^[A-Za-z]:\\(?:[^\\/:*?"<>|]+\\?)*$Absolute Windows pathよく使うパターン

    正規表現全体/^[A-Za-z]:\\(?:[^\\/:*?"<>|]+\\?)*$/g

    サンプルテキストC:\Users\alice

    一致結果C:\Users\alice1 件一致

  • \.\w+$File extensionよく使うパターン

    正規表現全体/\.\w+$/g

    サンプルテキストreport.pdf

    一致結果.pdf1 件一致

  • #[\w\u4e00-\u9fff]+Hashtag, Chinese and Englishよく使うパターン

    正規表現全体/#[\w\u4e00-\u9fff]+/g

    サンプルテキスト发帖 #unikit #工具 很好用

    一致結果#unikit#工具2 件一致

  • @[A-Za-z0-9_]{2,}@-mention handleよく使うパターン

    正規表現全体/@[A-Za-z0-9_]{2,}/g

    サンプルテキスト@alice @bob_2

    一致結果@alice@bob_22 件一致

  • \p{Emoji_Presentation}+Emoji characters (requires the u flag)よく使うパターン

    正規表現全体/\p{Emoji_Presentation}+/gu

    サンプルテキストhello 👍🎉 world

    一致結果👍🎉1 件一致

  • \.Escaped dot: matches a literal full stopエスケープと Unicode

    正規表現全体/\d+\.\d+/g

    サンプルテキストpi is 3.14

    一致結果3.141 件一致

  • \*Escaped star: matches a literal asteriskエスケープと Unicode

    正規表現全体/a\*b/g

    サンプルテキストa*b

    一致結果a*b1 件一致

  • \/Escaped slash, common in regex literalsエスケープと Unicode

    正規表現全体/^\/\w+/g

    サンプルテキスト/home

    一致結果/home1 件一致

  • \\Matches a single backslashエスケープと Unicode

    正規表現全体/\\/g

    サンプルテキストC:\Users

    一致結果\1 件一致

  • \nLine feed characterエスケープと Unicode

    正規表現全体/\n/g

    サンプルテキストline1 line2

    一致結果 1 件一致

  • \tTab characterエスケープと Unicode

    正規表現全体/\t/g

    サンプルテキストa b

    一致結果 1 件一致

  • \rCarriage return (CRLF text)エスケープと Unicode

    正規表現全体/\r/g

    サンプルテキストa b

    一致結果 1 件一致

  • \x41Two-digit hex escape: \x41 is Aエスケープと Unicode

    正規表現全体/\x41+/g

    サンプルテキストAAA

    一致結果AAA1 件一致

  • \u4e2dFour-digit Unicode escapeエスケープと Unicode

    正規表現全体/\u4e2d\u6587/g

    サンプルテキスト中文

    一致結果中文1 件一致

  • \u{1F600}Code point escape, requires the u flagエスケープと Unicode

    正規表現全体/\u{1F600}/gu

    サンプルテキスト😀

    一致結果😀1 件一致

  • \p{L}Unicode letter (requires the u flag)エスケープと Unicode

    正規表現全体/\p{L}+/gu

    サンプルテキスト中文 abc 123

    一致結果中文abc2 件一致

  • \p{Nd}Unicode decimal digit (needs the u flag)エスケープと Unicode

    正規表現全体/\p{Nd}+/gu

    サンプルテキストabc 123 中文

    一致結果1231 件一致

  • \P{L}The complement of \p{L}エスケープと Unicode

    正規表現全体/\P{L}+/gu

    サンプルテキストabc 123

    一致結果 1231 件一致

  • \p{Script=Han}Filter by script; Han means CJK ideographsエスケープと Unicode

    正規表現全体/\p{Script=Han}+/gu

    サンプルテキスト混合 han 汉字

    一致結果混合汉字2 件一致

このツールでできること

  • 正規表現を書いていて文法を忘れたとき:カテゴリ(文字クラス、量詞、グループと参照、断言、フラグ、よくあるパターン、エスケープと Unicode)ごとに見返せば十分です。
  • 各項目にはそのまま実行できる完全な正規表現とサンプルテキストが付いており、ページが一致結果をリアルタイムに表示するので、まずコンソールに貼り付けて試す必要はありません。
  • 「この正規表現が一致しないのはなぜか」を調べるときは同じ項目のサンプルと見比べ、フラグの付け忘れ(例えば g)か量詞の書き間違いかを確認できます。
  • キーワード検索で項目にたどり着けます:「メール」で検索すればよくあるパターンのメール正規表現が、「lookahead」で検索すればすべての先読みの書き方が並びます。

例

入力

キーワード「lookahead」で検索

出力

4 件:lookahead | (?=x) · negative-lookahead | (?!x) · password-lookaheads | (?=.*\d)(?=.*[a-z]) · lookahead-capture | (?=(\w+))

検索は大文字小文字を区別せず、構文・中英の説明・例の正規表現・id のすべてが照合対象です。例の正規表現は実行時に自動で g フラグが付きます。

よくある質問

全部でいくつの文法を収録していますか?

129 件で、7 つのカテゴリに分かれています:文字クラス 18 件、量詞 14 件、グループと参照 13 件、断言 17 件、フラグ 7 件、よくあるパターン 46 件、エスケープと Unicode 14 件。よくあるパターンにはメール、URL、電話番号など、そのまま使える完全な正規表現が含まれます。

例の一致結果はリアルタイムに計算されていますか?

はい。各例はページ内の JavaScript の正規表現エンジンで実行され、一致結果・キャプチャグループ・位置はすべて実際の実行結果で、あらかじめ書かれたテキストではありません。そのためブラウザーエンジンによる違いもそのまま見えます。

例の正規表現に g フラグが付いているのはなぜですか?

サンプルテキスト内のすべての一致を表示するためです。項目が持つフラグは g とマージして重複を除くので、例えばもともと i を使う項目は実行時に gi になり、意味を保ったまますべての一致を列挙できます。

1 つの例で最大いくつの一致を表示しますか?

最大 50 件です。これは壊滅的なバックトラックや長すぎるテキストでページが固まるのを防ぐためで、上限に達すると一致の探索を止め、無限にループしません。

ここにある文法はどのエンジンのものですか?

JavaScript の RegExp、つまり ECMAScript の方言です。言語ごとの違いは小さくなく、例えば Python の名前付きグループは (?P<name>)、Java の  の意味も少し異なります。他言語へ移植するときは確認してください。

キーワード:regexregexpcheat sheetlookahead

関連ツール