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
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]
  • 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

Code Generator

Generated Code

import re regex = re.compile(r"failing[\w\W]*?\d*\)\s[\w\W]*?\:\n[\s\S]*?(Assert[\w\W]*?)[\n].*(src\/[^:]+):(\d+):(\d+)") test_str = ("\n" "\n" " statement:propose\n" "  1) validates input\n\n\n" "  0 passing (1s)\n" " 1 failing\n\n" " 1) statement:propose validates input:\n" " AssertionError: expected { Object (status, err) } to have a deep property 'err' of 'err1', but got 'Error while fetching the changes from the event store: {\"error\":\"not_found\",\"reason\":\"missing\"}'\n" " at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:307:16)\n" " at .<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:255:21)\n" " at ctx.(anonymous function) [as property] (node_modules/chai/lib/chai/utils/overwriteMethod.js:49:33)\n" " at Context.<anonymous> (src/aggregate/test/index.js:21:36)\n" " at Request.init (node_modules/request/request.js:191:10)\n" " at new Request (node_modules/request/request.js:130:8)\n" " at request (node_modules/request/index.js:54:10)\n" " at Future._computation (src/aggregate/index.js:375:7)\n" " at FutureNode$fork [as _f] (node_modules/fluture/fluture.js:910:10)\n" " at FutureMap$fork [as _f] (node_modules/fluture/fluture.js:1239:26)\n" " at FutureChain$fork$res (node_modules/fluture/fluture.js:1188:18)\n" " at FutureMap$fork$res (node_modules/fluture/fluture.js:1240:7)\n" " at FutureNode$fork$done (node_modules/fluture/fluture.js:912:22)\n" " at node_modules/level-sublevel/shell.js:102:12\n" " at node_modules/level-sublevel/nut.js:122:19\n" " at Immediate.callNext (node_modules/memdown/memdown.js:173:5)\n" " at MemDOWN._get (node_modules/memdown/memdown.js:172:3)\n" " at MemDOWN.AbstractLevelDOWN.get (node_modules/abstract-leveldown/abstract-leveldown.js:94:17)\n" " at Object.get (node_modules/level-sublevel/nut.js:117:28)\n" " at EventEmitter.emitter.get (node_modules/level-sublevel/shell.js:100:9)\n" " at Future._computation (src/aggregate/index.js:368:49)\n" " at FutureNode$fork [as _f] (node_modules/fluture/fluture.js:910:10)\n" " at FutureMap$fork [as _f] (node_modules/fluture/fluture.js:1239:26)\n" " at FutureChain$fork$res (node_modules/fluture/fluture.js:1188:18)\n" " at FutureOf$fork [as _f] (node_modules/fluture/fluture.js:871:5)\n" " at FutureChain$fork$res (node_modules/fluture/fluture.js:1188:18)\n" " at FutureOf$fork [as _f] (node_modules/fluture/fluture.js:871:5)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureMap$fork [as _f] (node_modules/fluture/fluture.js:1239:26)\n" " at FutureMapRej$fork [as _f] (node_modules/fluture/fluture.js:1259:26)\n" " at Future$fork [as fork] (node_modules/fluture/fluture.js:252:17)\n" " at Seneca.<anonymous> (src/aggregate/index.js:205:10)\n" " at execute_action (node_modules/seneca/seneca.js:1092:20)\n" " at Object.act_fn [as fn] (node_modules/seneca/seneca.js:1042:11)\n" " at Immediate.processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at work_fn_callback (node_modules/gate-executor/gate-executor.js:195:7)\n" " at Seneca.reply (node_modules/seneca/seneca.js:1046:13)\n" " at src/aggregate/index.js:63:16\n" " at FutureNode$fork$done (node_modules/fluture/fluture.js:912:22)\n" " at node_modules/level-sublevel/shell.js:53:51\n" " at Immediate.<anonymous> (node_modules/level-sublevel/nut.js:109:13)\n" " at MemDOWN._batch (node_modules/memdown/memdown.js:208:3)\n" " at MemDOWN.AbstractLevelDOWN.batch (node_modules/abstract-leveldown/abstract-leveldown.js:189:17)\n" " at Object.apply (node_modules/level-sublevel/nut.js:87:23)\n" " at EventEmitter.emitter.put (node_modules/level-sublevel/shell.js:49:9)\n" " at Future._computation (src/aggregate/index.js:369:56)\n" " at FutureNode$fork [as _f] (node_modules/fluture/fluture.js:910:10)\n" " at FutureChainRej$fork$rej (node_modules/fluture/fluture.js:1219:18)\n" " at FutureNode$fork$done (node_modules/fluture/fluture.js:912:13)\n" " at node_modules/level-sublevel/shell.js:101:15\n" " at node_modules/level-sublevel/nut.js:121:19\n" " at Immediate.callNext (node_modules/memdown/memdown.js:166:47)\n" " at MemDOWN._get (node_modules/memdown/memdown.js:166:12)\n" " at MemDOWN.AbstractLevelDOWN.get (node_modules/abstract-leveldown/abstract-leveldown.js:94:17)\n" " at Object.get (node_modules/level-sublevel/nut.js:117:28)\n" " at EventEmitter.emitter.get (node_modules/level-sublevel/shell.js:100:9)\n" " at Future._computation (src/aggregate/index.js:368:49)\n" " at FutureNode$fork [as _f] (node_modules/fluture/fluture.js:910:10)\n" " at FutureChain$fork$res (node_modules/fluture/fluture.js:1188:18)\n" " at FutureOf$fork [as _f] (node_modules/fluture/fluture.js:871:5)\n" " at FutureChain$fork [as _f] (node_modules/fluture/fluture.js:1185:29)\n" " at FutureChainRej$fork [as _f] (node_modules/fluture/fluture.js:1216:29)\n" " at Future$fork [as fork] (node_modules/fluture/fluture.js:252:17)\n" " at Seneca.<anonymous> (src/aggregate/index.js:61:8)\n" " at execute_action (node_modules/seneca/seneca.js:1092:20)\n" " at Object.act_fn [as fn] (node_modules/seneca/seneca.js:1042:11)\n" " at processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at Immediate.<anonymous> (node_modules/gate-executor/gate-executor.js:240:7)\n" " at GateExecutor.self.start (node_modules/gate-executor/gate-executor.js:233:5)\n" " at Object.gate [as fn] (node_modules/gate-executor/gate-executor.js:329:10)\n" " at Immediate.processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at work_fn_callback (node_modules/gate-executor/gate-executor.js:195:7)\n" " at work_fn_callback (node_modules/gate-executor/gate-executor.js:186:11)\n" " at Seneca.reply (node_modules/seneca/seneca.js:1046:13)\n" " at Seneca.<anonymous> (src/state/index.js:49:12)\n" " at execute_action (node_modules/seneca/seneca.js:1092:20)\n" " at Object.act_fn [as fn] (node_modules/seneca/seneca.js:1042:11)\n" " at processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at Immediate.<anonymous> (node_modules/gate-executor/gate-executor.js:240:7)\n" " at GateExecutor.self.start (node_modules/gate-executor/gate-executor.js:233:5)\n" " at Object.gate [as fn] (node_modules/gate-executor/gate-executor.js:329:10)\n" " at Immediate.processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at work_fn_callback (node_modules/gate-executor/gate-executor.js:195:7)\n" " at work_fn_callback (node_modules/gate-executor/gate-executor.js:186:11)\n" " at Seneca.reply (node_modules/seneca/seneca.js:1046:13)\n" " at handle_inward_break (node_modules/seneca/seneca.js:1211:13)\n" " at execute_action (node_modules/seneca/seneca.js:1082:11)\n" " at Object.act_fn [as fn] (node_modules/seneca/seneca.js:1042:11)\n" " at processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at Immediate.<anonymous> (node_modules/gate-executor/gate-executor.js:240:7)\n" " at GateExecutor.self.start (node_modules/gate-executor/gate-executor.js:233:5)\n" " at Object.gate [as fn] (node_modules/gate-executor/gate-executor.js:329:10)\n" " at processor (node_modules/gate-executor/gate-executor.js:136:14)\n" " at Immediate.<anonymous> (node_modules/gate-executor/gate-executor.js:240:7)\n" " at GateExecutor.self.start (node_modules/gate-executor/gate-executor.js:233:5)\n" " at make_seneca (node_modules/seneca/seneca.js:507:6)\n" " at init (node_modules/seneca/seneca.js:224:16)\n" " at Object.<anonymous> (test/unit/helper.js:28:17)\n" " at loader (node_modules/babel-register/lib/node.js:144:5)\n" " at Object.require.extensions.(anonymous function) [as .js] (node_modules/babel-register/lib/node.js:154:7)\n" " at require (internal/module.js:20:19)\n" " at Array.forEach (native)\n" " at run (bootstrap_node.js:394:7)\n" " at startup (bootstrap_node.js:149:9)\n" " at bootstrap_node.js:509:3\n" "\n\n\n" "(node:11964) Warning: a promise was created in a handler at Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb-replicator/lib/index.js:87:24 but was not returned from it, see http://goo.gl/rRqMUw\n" " at new Promise (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/bluebird/js/release/promise.js:79:10)\n" "(node:11964) Warning: a promise was created in a handler at Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/express-pouchdb/lib/daemon-manager.js:28:16 but was not returned from it, see http://goo.gl/rRqMUw\n" " at Function.Promise.cast (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/bluebird/js/release/promise.js:196:13)\n" "(node:11964) Warning: a promise was created in a handler at Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/express-pouchdb/lib/daemon-manager.js:28:16 but was not returned from it, see http://goo.gl/rRqMUw\n" " at new Promise (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/bluebird/js/release/promise.js:79:10)\n" "(node:11964) Warning: a promise was rejected with a non-error: [object String]\n" "(node:11964) Warning: a promise was created in a handler at Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/express-pouchdb/lib/routes/authentication.js:96:7 but was not returned from it, see http://goo.gl/rRqMUw\n" " at new Promise (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/bluebird/js/release/promise.js:79:10)\n" "Unhandled rejection {\"status\":404,\"name\":\"not_found\",\"message\":\"missing\",\"reason\":\"missing\"}\n" " (No stack trace)\n" "From previous event:\n" " at PouchDB$5.<anonymous> (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:117:19)\n" " at PouchDB$5.get (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/argsarray/index.js:14:18)\n" " at PouchDB$5.<anonymous> (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb-wrappers/index.js:155:18)\n" " at securityWrapper (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb-security/lib/index.js:55:12)\n" " at callHandlers (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb-wrappers/index.js:447:17)\n" " at PouchDB$5.get (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb-wrappers/index.js:154:12)\n" " at Object.filter (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:3849:26)\n" " at Changes$2.doChanges (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:1638:45)\n" " at /Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:1598:12\n" " at Object.validate (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:3786:3)\n" " at Changes$2.validateChanges (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:1594:36)\n" " at /Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:1551:14\n" " at TaskQueue$1.execute (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:2580:7)\n" " at TaskQueue$1.ready (/Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:2593:8)\n" " at /Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:2740:20\n" " at /Users/jun/dev/OII/current/oi/code/aggregates/statement/node_modules/pouchdb/lib/index.js:4913:15\n" " at _combinedTickCallback (internal/process/next_tick.js:67:7)\n" " at process._tickCallback (internal/process/next_tick.js:98:9)\n" "Error while loading the aggregate state Error while fetching the changes from the event store: {\"error\":\"not_found\",\"reason\":\"missing\"}\n") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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