Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /^(.*?):(\d+):(\d*):?\s+(?:fatal\s+)?(warning|error):\s+(.*)$/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$', 'gm') const str = `[ 38%] Built target embedded_epjson_source [ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUEN673.cpp.o [ 38%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0002_factory.cpp.o [ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUGapDeflection.cpp.o [ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUGapLayer.cpp.o [ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUSolidDeflection.cpp.o In file included from /usr/include/c++/13/bits/hashtable_policy.h:36, from /usr/include/c++/13/bits/hashtable.h:35, from /usr/include/c++/13/bits/unordered_map.h:33, from /usr/include/c++/13/unordered_map:41, from /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/AirflowNetwork/include/AirflowNetwork/Solver.hpp:55, from /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:48: In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = char; _Up = char; bool _IsMove = false]’, inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = char*]’ at /usr/include/c++/13/bits/stl_algobase.h:506:30, inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = char*]’ at /usr/include/c++/13/bits/stl_algobase.h:533:42, inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = char*]’ at /usr/include/c++/13/bits/stl_algobase.h:540:31, inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = char*; _OI = char*]’ at /usr/include/c++/13/bits/stl_algobase.h:633:7, inlined from ‘static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = char*; _ForwardIterator = char*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:147:27, inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = char*; _ForwardIterator = char*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:185:15, inlined from ‘void fmt::v8::basic_memory_buffer<T, SIZE, Allocator>::grow(size_t) [with T = char; long unsigned int SIZE = 500; Allocator = std::allocator<char>]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/format.h:754:26, inlined from ‘void fmt::v8::detail::buffer<T>::try_reserve(size_t) [with T = char]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/core.h:842:39, inlined from ‘void fmt::v8::detail::buffer<T>::push_back(const T&) [with T = char]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/core.h:846:16, inlined from ‘std::string_view fmt::v8::formatter<{anonymous}::DoubleWrapper>::spec_builder()’ at /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/IOFiles.hh:144:25: /usr/include/c++/13/bits/stl_algobase.h:437:30: warning: ‘void* __builtin_memmove(void*, const void*, long unsigned int)’ writing between 2 and 9223372036854775807 bytes into a region of size 1 overflows the destination [-Wstringop-overflow=] 437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/c++allocator.h:33, from /usr/include/c++/13/bits/allocator.h:46, from /usr/include/c++/13/bits/alloc_traits.h:39, from /usr/include/c++/13/ext/alloc_traits.h:34, from /usr/include/c++/13/bits/hashtable_policy.h:39: In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = char]’, inlined from ‘static _Tp* std::allocator_traits<std::allocator<_Tp1> >::allocate(allocator_type&, size_type) [with _Tp = char]’ at /usr/include/c++/13/bits/alloc_traits.h:482:28, inlined from ‘void fmt::v8::basic_memory_buffer<T, SIZE, Allocator>::grow(size_t) [with T = char; long unsigned int SIZE = 500; Allocator = std::allocator<char>]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/format.h:752:49, inlined from ‘void fmt::v8::detail::buffer<T>::try_reserve(size_t) [with T = char]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/core.h:842:39, inlined from ‘void fmt::v8::detail::buffer<T>::push_back(const T&) [with T = char]’ at /home/runner/work/EnergyPlus/EnergyPlus/third_party/fmt-8.0.1/include/fmt/core.h:846:16, inlined from ‘std::string_view fmt::v8::formatter<{anonymous}::DoubleWrapper>::spec_builder()’ at /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/IOFiles.hh:144:25: /usr/include/c++/13/bits/new_allocator.h:151:55: note: destination object of size 1 allocated by ‘operator new’ 151 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); | ^ [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUSolidLayer.cpp.o [ 39%] Building CXX object src/EnergyPlus/AirflowNetwork/CMakeFiles/airflownetworklib.dir/src/Elements.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUVentilatedGapLayer.cpp.o [ 39%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0003.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IndoorEnvironment.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/LayerInterfaces.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/Layers.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/NonLinearSolver.cpp.o [ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/NusseltNumber.cpp.o [ 39%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0003_factory.cpp.o [ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/OutdoorEnvironment.cpp.o [ 40%] Building CXX object src/EnergyPlus/CMakeFiles/energyplusparser.dir/DataStringGlobals.cc.o [ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/PermeabilityFactor.cpp.o [ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SimpleIGU.cpp.o [ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SingleSystem.cpp.o [ 41%] Building CXX object src/EnergyPlus/CMakeFiles/energyplusparser.dir/FileSystem.cc.o [ 41%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SupportPillar.cpp.o [ 41%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/Surface.cpp.o [ 42%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/System.cpp.o [ 43%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0004.cpp.o`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions