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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?mi)^\s*#\s*cancel\s*duplicate.*\n" Local $sString = "---" & @CRLF & _ "# Mega-Linter GitHub Action configuration file" & @CRLF & _ "# More info at https://megalinter.github.io" & @CRLF & _ "name: Mega-Linter" & @CRLF & _ "" & @CRLF & _ "on:" & @CRLF & _ " # Trigger mega-linter at every push. Action will also be visible from Pull Requests to main" & @CRLF & _ " push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)" & @CRLF & _ " pull_request:" & @CRLF & _ " branches: [master, main]" & @CRLF & _ "" & @CRLF & _ "env: # Comment env block if you do not want to apply fixes" & @CRLF & _ " # Apply linter fixes configuration" & @CRLF & _ " APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)" & @CRLF & _ " APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)" & @CRLF & _ " APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)" & @CRLF & _ "" & @CRLF & _ "concurrency:" & @CRLF & _ " group: ${{ github.ref }}-${{ github.workflow }}" & @CRLF & _ " cancel-in-progress: true" & @CRLF & _ "" & @CRLF & _ "jobs:" & @CRLF & _ " # Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only" & @CRLF & _ " build:" & @CRLF & _ " name: Mega-Linter" & @CRLF & _ " runs-on: ubuntu-latest" & @CRLF & _ " steps:" & @CRLF & _ " # Git Checkout" & @CRLF & _ " - name: Checkout Code" & @CRLF & _ " uses: actions/checkout@v2" & @CRLF & _ " with:" & @CRLF & _ " token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}" & @CRLF & _ " fetch-depth: 0" & @CRLF & _ "" & @CRLF & _ " # Mega-Linter" & @CRLF & _ " - name: Mega-Linter" & @CRLF & _ " id: ml" & @CRLF & _ " # You can override Mega-Linter flavor used to have faster performances" & @CRLF & _ " # More info at https://megalinter.github.io/flavors/" & @CRLF & _ " uses: megalinter/megalinter@v5" & @CRLF & _ " env:" & @CRLF & _ " # All available variables are described in documentation" & @CRLF & _ " # https://megalinter.github.io/configuration/" & @CRLF & _ " VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources" & @CRLF & _ " GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}" & @CRLF & _ " # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY" & @CRLF & _ " # DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks" & @CRLF & _ "" & @CRLF & _ " # Upload Mega-Linter artifacts" & @CRLF & _ " - name: Archive production artifacts" & @CRLF & _ " if: ${{ success() }} || ${{ failure() }}" & @CRLF & _ " uses: actions/upload-artifact@v2" & @CRLF & _ " with:" & @CRLF & _ " name: Mega-Linter reports" & @CRLF & _ " path: |" & @CRLF & _ " report" & @CRLF & _ " mega-linter.log" & @CRLF & _ "" & @CRLF & _ " # Create pull request if applicable (for now works only on PR from same repository, not from forks)" & @CRLF & _ " - name: Create Pull Request with applied fixes" & @CRLF & _ " id: cpr" & @CRLF & _ " if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)" & @CRLF & _ " uses: peter-evans/create-pull-request@v3" & @CRLF & _ " with:" & @CRLF & _ " token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}" & @CRLF & _ " commit-message: "[Mega-Linter] Apply linters automatic fixes"" & @CRLF & _ " title: "[Mega-Linter] Apply linters automatic fixes"" & @CRLF & _ " labels: bot" & @CRLF & _ " - name: Create PR output" & @CRLF & _ " if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)" & @CRLF & _ " run: |" & @CRLF & _ " echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"" & @CRLF & _ " echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"" & @CRLF & _ "" & @CRLF & _ " # Push new commit if applicable (for now works only on PR from same repository, not from forks)" & @CRLF & _ " - name: Prepare commit" & @CRLF & _ " if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)" & @CRLF & _ " run: sudo chown -Rc $UID .git/" & @CRLF & _ " - name: Commit and push applied linter fixes" & @CRLF & _ " if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)" & @CRLF & _ " uses: stefanzweifel/git-auto-commit-action@v4" & @CRLF & _ " with:" & @CRLF & _ " branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}" & @CRLF & _ " commit_message: "[Mega-Linter] Apply linters fixes"" & @CRLF & _ "" Local $sSubst = "" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm