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

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)buffer_1" Local $sString = "/*" & @CRLF & _ " * To change this license header, choose License Headers in Project Properties." & @CRLF & _ " * To change this template file, choose Tools | Templates" & @CRLF & _ " * and open the template in the editor." & @CRLF & _ " */" & @CRLF & _ "package kythuatlaptrinhat;" & @CRLF & _ "" & @CRLF & _ "import java.util.Random;" & @CRLF & _ "import java.util.Scanner;" & @CRLF & _ "" & @CRLF & _ "/**" & @CRLF & _ " *" & @CRLF & _ " * @author shadyside" & @CRLF & _ " */" & @CRLF & _ "public class Bai2Lab1 {" & @CRLF & _ "" & @CRLF & _ " public static void main(String[] args) {" & @CRLF & _ " Scanner input = new Scanner(System.in);" & @CRLF & _ "" & @CRLF & _ " System.out.println("Nhap chieu dai mang:");" & @CRLF & _ " int inputLen = input.nextInt();" & @CRLF & _ " int[] inputArray = inputArray(inputLen);" & @CRLF & _ "" & @CRLF & _ " System.out.println("Mảng nguồn: ");" & @CRLF & _ " printArray(inputArray);" & @CRLF & _ " System.out.println("Nhập điểm bắt đầu sao chép: ");" & @CRLF & _ " int start = input.nextInt();" & @CRLF & _ " System.out.println("Nhập điểm kết thúc: ");" & @CRLF & _ " int end = input.nextInt();" & @CRLF & _ " System.out.println("Nhập chiều dài mảng đích");" & @CRLF & _ " int outputLen = input.nextInt();" & @CRLF & _ " int[] ouputArray = inputArray(outputLen);" & @CRLF & _ "" & @CRLF & _ " System.out.println("Nhập vị trí bắt đầu thêm dữ liệu");" & @CRLF & _ " int startOfCopy = input.nextInt();" & @CRLF & _ "" & @CRLF & _ " System.out.println("Mảng đích ban đầu: ");" & @CRLF & _ " printArray(ouputArray);" & @CRLF & _ " System.out.println("-------------------------");" & @CRLF & _ " System.out.println("Ket qua:");" & @CRLF & _ " System.out.println("Mảng nguồn: ");" & @CRLF & _ " printArray(inputArray);" & @CRLF & _ " int[] result = copyArray(inputArray, inputLen, start, end, ouputArray, outputLen, startOfCopy);" & @CRLF & _ " if (result == null) {" & @CRLF & _ " System.out.println("Có lỗi xảy ra");" & @CRLF & _ " } else {" & @CRLF & _ " System.out.println("Mảng đích: ");" & @CRLF & _ " printArray(result);" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " public static int[] copyArray(int[] inputArray, int inputLen, int start, int end, int[] outputArray, int outpuLen, int startOfCopy) {" & @CRLF & _ " if (start >= 0 && end <= inputLen && startOfCopy >= 0 && startOfCopy <= outpuLen && start <= end) {" & @CRLF & _ " /*" & @CRLF & _ " *Trường hợp số lượng cần copy trong mảng nguồn nhỏ hơn số phần tử còn trống trong mảng đích" & @CRLF & _ " */" & @CRLF & _ " if ((end - start + 1) < (outpuLen - startOfCopy - 1)) {" & @CRLF & _ " /*" & @CRLF & _ " * Thực hiện dịch các phần tử" & @CRLF & _ " */" & @CRLF & _ " for (int i = outpuLen; i > startOfCopy + (end - start + 1) + 1; i--) {" & @CRLF & _ " outputArray[i - 1] = outputArray[i - 1 - (end - start + 1)];" & @CRLF & _ " }" & @CRLF & _ " /*" & @CRLF & _ " * Copy các phần tử vào mảng đích" & @CRLF & _ " */" & @CRLF & _ " for (int i = start; i <= end; i++) {" & @CRLF & _ " outputArray[startOfCopy + 1 + (i - start)] = inputArray[i];" & @CRLF & _ " }" & @CRLF & _ " System.out.println("So gia tri duoc sao chep: " + (end - start + 1));" & @CRLF & _ " }" & @CRLF & _ " /*" & @CRLF & _ " *Trường hợp số lượng cần copy trong mảng nguồn bằng số phần tử còn trống trong mảng đích" & @CRLF & _ " */" & @CRLF & _ " else if ((end - start + 1) == (outpuLen - startOfCopy - 1)) {" & @CRLF & _ " for (int i = start; i <= end; i++) {" & @CRLF & _ " outputArray[startOfCopy + (i - start)] = inputArray[i];" & @CRLF & _ " }" & @CRLF & _ " } " & @CRLF & _ " /*" & @CRLF & _ " *Trường hợp số lượng cần copy trong mảng nguồn lớn hơn số phần tử còn trống trong mảng đích" & @CRLF & _ " */" & @CRLF & _ " else {" & @CRLF & _ " for (int i = start; i < start + (outpuLen - startOfCopy); i++) {" & @CRLF & _ " outputArray[startOfCopy + (i - start)] = inputArray[i];" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " return outputArray;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " public static int[] inputArray(int len) {" & @CRLF & _ " int[] inputArray = new int[len];" & @CRLF & _ " Random random = new Random();" & @CRLF & _ " for (int i = 0; i < len; i++) {" & @CRLF & _ " inputArray[i] = random.nextInt(100);" & @CRLF & _ " }" & @CRLF & _ " return inputArray;" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " public static void printArray(int[] a) {" & @CRLF & _ " for (int i = 0; i < a.length; i++) {" & @CRLF & _ " System.out.print(a[i] + " ");" & @CRLF & _ " }" & @CRLF & _ " System.out.println("");" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ "}" & @CRLF & _ "" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm