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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$"; final String string = "[ 38%] Built target embedded_epjson_source\n" + "[ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUEN673.cpp.o\n" + "[ 38%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0002_factory.cpp.o\n" + "[ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUGapDeflection.cpp.o\n" + "[ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUGapLayer.cpp.o\n" + "[ 38%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUSolidDeflection.cpp.o\n" + "In file included from /usr/include/c++/13/bits/hashtable_policy.h:36,\n" + " from /usr/include/c++/13/bits/hashtable.h:35,\n" + " from /usr/include/c++/13/bits/unordered_map.h:33,\n" + " from /usr/include/c++/13/unordered_map:41,\n" + " from /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/AirflowNetwork/include/AirflowNetwork/Solver.hpp:55,\n" + " from /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/AirflowNetwork/src/Solver.cpp:48:\n" + "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]’,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = char*; _OI = char*]’ at /usr/include/c++/13/bits/stl_algobase.h:633:7,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " inlined from ‘std::string_view fmt::v8::formatter<{anonymous}::DoubleWrapper>::spec_builder()’ at /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/IOFiles.hh:144:25:\n" + "/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=]\n" + " 437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);\n" + " | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/c++allocator.h:33,\n" + " from /usr/include/c++/13/bits/allocator.h:46,\n" + " from /usr/include/c++/13/bits/alloc_traits.h:39,\n" + " from /usr/include/c++/13/ext/alloc_traits.h:34,\n" + " from /usr/include/c++/13/bits/hashtable_policy.h:39:\n" + "In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = char]’,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " 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,\n" + " inlined from ‘std::string_view fmt::v8::formatter<{anonymous}::DoubleWrapper>::spec_builder()’ at /home/runner/work/EnergyPlus/EnergyPlus/src/EnergyPlus/IOFiles.hh:144:25:\n" + "/usr/include/c++/13/bits/new_allocator.h:151:55: note: destination object of size 1 allocated by ‘operator new’\n" + " 151 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp)));\n" + " | ^\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUSolidLayer.cpp.o\n" + "[ 39%] Building CXX object src/EnergyPlus/AirflowNetwork/CMakeFiles/airflownetworklib.dir/src/Elements.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IGUVentilatedGapLayer.cpp.o\n" + "[ 39%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0003.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/IndoorEnvironment.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/LayerInterfaces.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/Layers.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/NonLinearSolver.cpp.o\n" + "[ 39%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/NusseltNumber.cpp.o\n" + "[ 39%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0003_factory.cpp.o\n" + "[ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/OutdoorEnvironment.cpp.o\n" + "[ 40%] Building CXX object src/EnergyPlus/CMakeFiles/energyplusparser.dir/DataStringGlobals.cc.o\n" + "[ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/PermeabilityFactor.cpp.o\n" + "[ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SimpleIGU.cpp.o\n" + "[ 40%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SingleSystem.cpp.o\n" + "[ 41%] Building CXX object src/EnergyPlus/CMakeFiles/energyplusparser.dir/FileSystem.cc.o\n" + "[ 41%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/SupportPillar.cpp.o\n" + "[ 41%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/Surface.cpp.o\n" + "[ 42%] Building CXX object third_party/Windows-CalcEngine/CMakeFiles/Windows-CalcEngine.dir/src/Tarcog/src/System.cpp.o\n" + "[ 43%] Building CXX object third_party/libtk205/src/CMakeFiles/libtk205.dir/rs0004.cpp.o"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html