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
No Match

r"
"

Test String

Substitution

Processing...

Code Generator

Generated Code

# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression. sed -E 's/(?:(?:\n)?[^\n]*){0,22}//;t' <<< "/* * Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser * * Developed for use with the book: * * Data Structures and Algorithms in Java, Sixth Edition * Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser * John Wiley & Sons, 2014 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dsaj.arrays; import java.util.Arrays; /** Class for doing encryption and decryption using the Caesar Cipher. */ public class CaesarCipher { protected char[] encoder = new char[26]; // Encryption array protected char[] decoder = new char[26]; // Decryption array /** Constructor that initializes the encryption and decryption arrays */ public CaesarCipher(int rotation) { for (int k=0; k < 26; k++) { encoder[k] = (char) ('A' + (k + rotation) % 26); decoder[k] = (char) ('A' + (k - rotation + 26) % 26); } } /** Returns String representing encrypted message. */ public String encrypt(String message) { return transform(message, encoder); // use encoder array } /** Returns decrypted message given encrypted secret. */ public String decrypt(String secret) { return transform(secret, decoder); // use decoder array } /** Returns transformation of original String using given code. */ private String transform(String original, char[] code) { char[] msg = original.toCharArray(); for (int k=0; k < msg.length; k++) if (Character.isUpperCase(msg[k])) { // we have a letter to change int j = msg[k] - 'A'; // will be value from 0 to 25 msg[k] = code[j]; // replace the character } return new String(msg); } /** Simple main method for testing the Caesar cipher */ public static void main(String[] args) { CaesarCipher cipher = new CaesarCipher(3); System.out.println(\"Encryption code = \" + new String(cipher.encoder)); System.out.println(\"Decryption code = \" + new String(cipher.decoder)); String message = \"THE EAGLE IS IN PLAY; MEET AT JOE'S.\"; String coded = cipher.encrypt(message); System.out.println(\"Secret: \" + coded); String answer = cipher.decrypt(coded); System.out.println(\"Message: \" + answer); // should be plaintext again } } "

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 SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html