Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
g

Test String

Code Generator

Generated Code

$re = '/[幹乾淦贛干肏操糙去草塞賽]?[林賃吝零靈齡拎恁你他她它祂牠]([馬马量梁良糧涼娘妹媽]|老[師蘇詩屍濕溼]|奶奶|祖?(嬤|媽|罵))(的|樂|叻|垃|勒|咧|([基唧雞機激][掰歪]))?|[靠尻哭][杯倍背貝輩悖北盃悲卑揹腰邀妖夭幺么]|([基唧雞機激](車|[教轎窖嶠叫較趴葩]|[掰歪]))|(([魯盧擄虜盧爐]|[假呷吃甲賈卡]|[衝沖充銃欉謥]?[三殺沙砂啥])[小洨曉])|(破[麻目])|([俗卒][仔臘辣])|[賤屌肏操糙]|(幹(?![麻嘛嗎]|(啥|[蛇神什甚]麼|[好壞]事)))|(靠(?!在|的|他|你|妳|她))|([林賃吝拎恁你][霸爸北背])|([懶藍覽攬欖][教轎窖嶠叫較趴葩])|([白北度杜渡肚虎唬][爛濫纜藍覽懶])|(智[缺障仗丈瘴])|(去你的)|((?i)GG\s?IN\s?IN)|(想[樓揉])|(ㄈㄈ尺)|((?i)ccr|fuck|hell|shit|ass(hole)?|idiot|damn|bitch|phycho|bastard|Whore|Slut)/'; $str = '幹 幹嘛 幹麻 幹甚麼好事 幹他媽的 幹你娘 乾 乾淨 乾林老師 靠 靠北 靠你了 靠北邊 靠杯 靠背 靠盃 靠腰 靠夭 哭夭 幹靈糧 去你的 去你媽的 林北 恁北 恁娘 恁祖媽 機掰 賤 俗辣 他媽的 覽趴 懶趴 北爛 盧小 魯洨 色龜 肚爛 放屁 屁股 屌 啥小 三小 操 屁 唬爛 龜公 他奶奶的 犯賤 機車 智缺 你娘卡好 林老師 破麻 賽 操卒仔 操機歪 糙機掰 無懶趴 卡小 吃小 死魚眼 炭甲查某 糙你妹 GGININ GG IN IN GG IN IN DER gginin 可惡 想揉 想揉 ㄈㄈ尺 英文原生: CCR Fuck off Fuck mother fucker You SOB son of a bitch Go to hell Shit-head Asshole You beast Shit fart Idiot damn it God damn God damn it hypocrite ass hole ass licker bitch phycho bastard Whore Slut Shit-head '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php