Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

import re regex = re.compile(r"^(.*?)\[(.*?)(\(.*?\).*?)\]$", flags=re.MULTILINE) test_str = ("### **UPSC Related Key Points and Key Facts**\n\n" "---\n\n" "#### **1. Background and Formation of Jharkhand**\n" "- **Carved Out of Bihar:**\n" " - Formed on **November 15, 2000**, during PM Atal Bihari Vajpayee's tenure. \n" " - Alongside Chhattisgarh (from Madhya Pradesh) and Uttarakhand (from Uttar Pradesh). \n" " - Created to address tribal and regional aspirations, coinciding with **Birsa Munda's birth anniversary.**\n\n" "- **Structure Post-Bifurcation:**\n" " - Comprises **18 of Bihar’s 55 districts.**\n" " - Has **81 Assembly seats** and **14 Lok Sabha seats.**\n" " - Rich in mineral resources, but socioeconomically underdeveloped.\n\n" "- **Historical Demand:**\n" " - Tribal leader **Jaipal Singh Munda’s Jharkhand Party** fought for a separate state post-Independence. \n" " - Demand was initially rejected by the **States Reorganisation Commission** citing economic and agricultural concerns.\n\n" "---\n\n" "#### **2. Political Landscape and Turmoil**\n" "- **Dominant Parties:**\n" " - **BJP** and **Jharkhand Mukti Morcha (JMM)** dominate state politics. \n" " - Other players: Congress, RJD, CPI, and **Jharkhand Vikas Morcha-Prajatantrik (JVM-P)** (formed by Babulal Marandi).\n\n" "- **Chief Ministers:**\n" " - Jharkhand has had **seven CMs** since 2000, reflecting political instability. \n" " - Only **Raghubar Das** (BJP, 2014-2019) completed a full term. \n\n" "---\n\n" "#### **3. Electoral and Political History**\n" "- **2000-2005: Early Instability**\n" " - **Babulal Marandi (BJP):** First CM, but infighting led to his replacement by **Arjun Munda (BJP)** in 2003.\n" " - In 2005, JMM leader **Shibu Soren** briefly became CM but resigned within 10 days due to lack of majority.\n\n" "- **2006-2014: Turmoil and Alliances**\n" " - **Madhu Koda (Independent):** Became CM in 2006 but lost power after corruption allegations. \n" " - Frequent switches between Presidents' Rule and short-lived alliances involving BJP, JMM, Congress, and Independents. \n" " - **Hemant Soren (JMM):** Became CM in 2013 for the first time after breaking with BJP.\n\n" "- **2014-2019: BJP Consolidation**\n" " - **Raghubar Das (BJP):** First non-tribal CM, completed a five-year term.\n" " - BJP’s 2014 Assembly win was driven by the **Narendra Modi wave.**\n\n" "- **2019-Present: JMM Resurgence**\n" " - **Hemant Soren (JMM):** Returned as CM after JMM-Congress alliance secured a majority. \n" " - Accusations of corruption led to his temporary resignation; **Champai Soren** served briefly as CM.\n\n" "---\n\n" "#### **4. Challenges in Jharkhand’s Politics**\n" "- **Fragmentation and Alliances:**\n" " - No single party has won a clear majority in any Assembly election so far.\n" " - Frequent changes in government due to defections and coalition instability.\n\n" "- **Tribal vs Non-Tribal Leadership:**\n" " - Tribal leaders (Babulal Marandi, Hemant Soren) dominate discourse, but BJP experimented with a non-tribal CM in Raghubar Das.\n\n" "- **Corruption and Governance Issues:**\n" " - Several leaders, including Madhu Koda and Hemant Soren, have faced allegations of corruption.\n" " - Political instability has hindered long-term development.\n\n" "---\n\n" "#### **5. Current Political Scenario**\n" "- **BJP:**\n" " - Led by **Babulal Marandi**, who returned to BJP in 2019 after leading JVM-P. \n" " - Raghubar Das now serves as Governor of Odisha.\n\n" "- **JMM:**\n" " - Hemant Soren continues to lead despite controversies, but internal rifts remain a concern. \n" " - Competing demands from tribal and non-tribal sections persist.\n\n" "---\n\n" "### **Mermaid Diagram**\n\n" "```mermaid\n" "graph LR\n" "A[Formation of Jharkhand (2000)] --> B[Reasons for Creation]\n" "B --> B1[Tribal Aspirations]\n" "B --> B2[Birsa Munda Legacy]\n" "B --> B3[Rich Mineral Resources]\n\n" "A --> C[Political Landscape]\n" "C --> C1[BJP Dominance]\n" "C --> C2[JMM as Key Rival]\n" "C --> C3[Congress and Regional Players]\n\n" "A --> D[Timeline of Chief Ministers]\n" "D --> D1[Babulal Marandi (2000-2003)]\n" "D --> D2[Arjun Munda (2003-2005, 2010-2013)]\n" "D --> D3[Madhu Koda (2006-2008)]\n" "D --> D4[Hemant Soren (2013-Present)]\n\n" "A --> E[Challenges]\n" "E --> E1[Frequent Political Instability]\n" "E --> E2[Corruption Allegations]\n" "E --> E3[Tribal vs Non-Tribal Leadership]\n\n" "A --> F[Recent Developments]\n" "F --> F1[Babulal Marandi Returns to BJP]\n" "F --> F2[Hemant Soren Faces Corruption Allegations]\n" "F --> F3[Tribal Discontent and Economic Challenges]\n" "``` \n") subst = "\\1\\[\\\"\\2\\3\\\"]" result = regex.sub(subst, test_str) if result: print(result)

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 Python, please visit: https://docs.python.org/3/library/re.html