Regular Expressions 101

Save & Share

  • Regex Version: ver. 31
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
g

Test String

Code Generator

Generated Code

$re = '/(?<=^|[\n;](?:[\t ]*(?:\w+ )?)?)import\s*(?<type>type(?=\s+))?(?:[\s"\']*(?<imports>[\w\t\n\r "$\'*,/{}-]+?)\s+from\s*)?["\']\s*(?<specifier>(?:(?<=\'\s*)[^\']*[^\s\'](?=\s*\'))|(?:(?<="\s*)[^"]*[^\s"](?=\s*")))\s*["\'](?:\s+assert\s+(?<assertion>{[\w\t\n\r "\':]+?}))?(?=[\s;]*)/'; $str = '/** * @file Interfaces * @module mlly/interfaces */ export type { default as DynamicImport } from \'./import-dynamic\' export type { default as StaticImport } from \'./import-static\' export type { default as ResolveOptions } from \'./options-resolve\' export type { default as ResolveAliasOptions } from \'./options-resolve-alias\' export type { default as Statement } from \'./statement\' export type { default as ExportStatement } from \'./statement-export\' export type { default as ImportStatement } from \'./statement-import\' export type { default as RequireStatement } from \'./statement-require\' import { CONDITIONS, RESOLVE_EXTENSIONS } from \'#src/constants\' import type { ResolveOptions } from \'#src/interfaces\' import type { SpecifierType } from \'#src/types\' import isBuiltin from \'@flex-development/is-builtin\' import { moduleResolve, type ErrnoException } from \'import-meta-resolve\' import { pathToFileURL, URL } from \'node:url\' import upath from \'upath\' import toBareSpecifier from \'./to-bare-specifier\' import toRelativeSpecifier from \'./to-relative-specifier\' import \'file:///home/dir/file.ts\' import pkg from \'./package.json\' assert { type:\'json\' } import * as color from \'colorette\' import consola from \'consola\' import { defu } from \'defu\' import type { Format } from \'esbuild\' import fse from \'fs-extra\' import * as pathe from \'pathe\' import { resolve } from \'node:path\' import url from \'node:url\' import type { PackageJson } from \'pkg-types\' import pb from \'pretty-bytes\' import { EXT_DTS_REGEX, IGNORE_PATTERNS } from \'./config/constants\' import loadBuildConfig from \'./config/load\' import type { Config, Entry, Result } from \'./interfaces\' import type { OutputExtension } from \'./types\' import { readPackage, type PackageJson } from "read-pkg" import {OutputExtension} from \'./types\' import analyzeResults from \'./utils/analyze-results\' import esbuilder from \'./utils/esbuilder\'; import write from \'./utils/write\';import write2 from \'./utils/write\' // import write from \'./utils/write\' import \'side-effect.mjs\' import type StatementType from \'../types/statement-type\' import type { BuildOptions, BuildResult, OutputFile, Plugin, PluginBuild } from \'./esbuild\' import defaultExport from "module-name"; import * as name from "module-name"; import { export1 } from "module-name"; import { export1 as alias1 } from "module-name"; import { default as alias } from "module-name"; import { export1, export2 } from "module-name"; import { export1, export2 as alias2 } from "module-name"; import { \'string name\' as alias } from "module-name"; import { "string name" as alias } from "module-name"; import defaultExport, { export1 } from "module-name"; import defaultExport, * as name from "module-name"; import "module-name"; import \'module-name\'; import \'./polyfill.mjs\' import { "h-i" as hi } from \'./hi.js\' import { \'j-k\' as jk } from "./jk.js" declare module \'__fixtures__/values\' { import MAX_VALUE from \'#fixtures/max-value\' import MIN_VALUE from \'#fixtures/min-value\' } const ERR_UNSUPPORTED_DIR_IMPORT: NodeErrorConstructor< ErrorConstructor, [string, string] > = createNodeError( ErrorCode.ERR_UNSUPPORTED_DIR_IMPORT, Error, \'Directory import \'%s\' is not supported resolving ES modules imported from %s\' ) const text: string = await resolveModules(output.text, { conditions: [format === \'esm\' ? \'import\' : \'require\'], ext: ext as Ext, extensions, parent }) /** * @example * import write from \'./utils/write\' * write() */ import { \'j-k\' as jk } from "./jk.js"'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php