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

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

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html