Regular Expressions 101

Save & Share

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

/
/
gmiuJ

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 = "(?miuJ)(class+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?" Local $sString = "<div>" & @CRLF & _ " @if($beforeTableSlot)" & @CRLF & _ " <div class="mt-8">" & @CRLF & _ " @include($beforeTableSlot)" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " <div class="relative">" & @CRLF & _ " <div class="flex justify-between items-center mb-1">" & @CRLF & _ " <div class="flex-grow h-10 flex items-center">" & @CRLF & _ " @if($this->searchableColumns()->count())" & @CRLF & _ " <div class="w-96 flex rounded-lg shadow-sm">" & @CRLF & _ " <div class="relative flex-grow focus-within:z-10">" & @CRLF & _ " <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">" & @CRLF & _ " <svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" stroke="currentColor" fill="none">" & @CRLF & _ " <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />" & @CRLF & _ " </svg>" & @CRLF & _ " </div>" & @CRLF & _ " <input wire:model.debounce.500ms="search" class="w-full pl-10 py-3 text-sm leading-4 block rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50 focus:outline-none" placeholder="{{__('Search in')}} {{ $this->searchableColumns()->map->label->join(', ') }}" type="text" />" & @CRLF & _ " <div class="absolute inset-y-0 right-0 pr-2 flex items-center">" & @CRLF & _ " <button wire:click="$set('search', null)" class="text-gray-300 hover:text-red-600 focus:outline-none">" & @CRLF & _ " <x-icons.x-circle class="h-5 w-5 stroke-current" />" & @CRLF & _ " </button>" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " <div class="flex items-center space-x-1">" & @CRLF & _ " <x-icons.cog wire:loading class="h-9 w-9 animate-spin text-gray-400" />" & @CRLF & _ "" & @CRLF & _ " @if($exportable)" & @CRLF & _ " <div x-data="{ init() {" & @CRLF & _ " window.livewire.on('startDownload', link => window.open(link,'_blank'))" & @CRLF & _ " } }" x-init="init">" & @CRLF & _ " <button wire:click="export" class="flex items-center space-x-2 px-3 border border-green-400 rounded-md bg-white text-green-500 text-xs leading-4 font-medium uppercase tracking-wider hover:bg-green-200 focus:outline-none"><span>{{ __('Export') }}</span>" & @CRLF & _ " <x-icons.excel class="m-2" /></button>" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ "" & @CRLF & _ " @if($hideable === 'select')" & @CRLF & _ " @include('datatables::hide-column-multiselect')" & @CRLF & _ " @endif" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " @if($hideable === 'buttons')" & @CRLF & _ " <div class="p-2 grid grid-cols-8 gap-2">" & @CRLF & _ " @foreach($this->columns as $index => $column)" & @CRLF & _ " <button wire:click.prefetch="toggle('{{ $index }}')" class="px-3 py-2 rounded text-white text-xs focus:outline-none" & @CRLF & _ " {{ $column['hidden'] ? 'bg-blue-100 hover:bg-blue-300 text-blue-600' : 'bg-blue-500 hover:bg-blue-800' }}">" & @CRLF & _ " {{ $column['label'] }}" & @CRLF & _ " </button>" & @CRLF & _ " @endforeach" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ "" & @CRLF & _ " <div class="rounded-lg shadow-lg bg-white max-w-screen overflow-auto">" & @CRLF & _ " <div class="rounded-lg @unless($this->hidePagination) rounded-b-none @endif">" & @CRLF & _ " <div class="table align-middle min-w-full">" & @CRLF & _ " @unless($this->hideHeader)" & @CRLF & _ " <div class="table-row divide-x divide-gray-200">" & @CRLF & _ " @foreach($this->columns as $index => $column)" & @CRLF & _ " @if($hideable === 'inline')" & @CRLF & _ " @include('datatables::header-inline-hide', ['column' => $column, 'sort' => $sort])" & @CRLF & _ " @elseif($column['type'] === 'checkbox')" & @CRLF & _ " @unless($column['hidden'])" & @CRLF & _ " <div class="w-32 py-4 flex justify-center overflow-hidden align-top px-6 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider focus:outline-none">" & @CRLF & _ " <div class="px-3 py-1 rounded @if(count($selected)) bg-orange-400 @else bg-gray-200 @endif text-white text-center">" & @CRLF & _ " {{ count($selected) }}" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @endunless" & @CRLF & _ " @else" & @CRLF & _ " @include('datatables::header-no-hide', ['column' => $column, 'sort' => $sort])" & @CRLF & _ " @endif" & @CRLF & _ " @endforeach" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " <div class="table-row divide-x divide-blue-200 bg-blue-100">" & @CRLF & _ " @foreach($this->columns as $index => $column)" & @CRLF & _ " @if($column['hidden'])" & @CRLF & _ " @if($hideable === 'inline')" & @CRLF & _ " <div class="table-cell w-5 overflow-hidden align-top bg-blue-100"></div>" & @CRLF & _ " @endif" & @CRLF & _ " @elseif($column['type'] === 'checkbox')" & @CRLF & _ " <div class="overflow-hidden align-top bg-blue-100 px-6 py-5 border-b border-gray-200 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider flex h-full flex-col items-center space-y-2 focus:outline-none">" & @CRLF & _ " <div>SELECT ALL</div>" & @CRLF & _ " <div>" & @CRLF & _ " <input type="checkbox" wire:click="toggleSelectAll" @if(count($selected) === $this->results->total()) checked @endif class="form-checkbox mt-1 h-4 w-4 text-blue-600 transition duration-150 ease-in-out" />" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @else" & @CRLF & _ " <div class="table-cell overflow-hidden align-top">" & @CRLF & _ " @isset($column['filterable'])" & @CRLF & _ " @if( is_iterable($column['filterable']) )" & @CRLF & _ " <div wire:key="{{ $index }}">" & @CRLF & _ " @include('datatables::filters.select', ['index' => $index, 'name' => $column['label'], 'options' => $column['filterable']])" & @CRLF & _ " </div>" & @CRLF & _ " @else" & @CRLF & _ " <div wire:key="{{ $index }}">" & @CRLF & _ " @include('datatables::filters.' . ($column['filterView'] ?? $column['type']), ['index' => $index, 'name' => $column['label']])" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " @endisset" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " @endforeach" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " @forelse($this->results as $result)" & @CRLF & _ " <div class="table-row p-1 divide-x divide-gray-100 {{ isset($result->checkbox_attribute) && in_array($result->checkbox_attribute, $selected) ? 'bg-orange-100' : ($loop->even ? 'bg-gray-100' : 'bg-gray-50') }}">" & @CRLF & _ " @foreach($this->columns as $column)" & @CRLF & _ " @if($column['hidden'])" & @CRLF & _ " @if($hideable === 'inline')" & @CRLF & _ " <div class="table-cell w-5 overflow-hidden align-top"></div>" & @CRLF & _ " @endif" & @CRLF & _ " @elseif($column['type'] === 'checkbox')" & @CRLF & _ " @include('datatables::checkbox', ['value' => $result->checkbox_attribute])" & @CRLF & _ " @else" & @CRLF & _ " <div class="px-6 py-2 whitespace-no-wrap text-sm leading-5 text-gray-900 table-cell @if($column['align'] === 'right') text-right @elseif($column['align'] === 'center') text-center @else text-left @endif">" & @CRLF & _ " {!! $result->{$column['name']} !!}" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " @endforeach" & @CRLF & _ " </div>" & @CRLF & _ " @empty" & @CRLF & _ " <p class="p-3 text-lg text-teal-600">" & @CRLF & _ " {{ __("There's Nothing to show at the moment") }}" & @CRLF & _ " </p>" & @CRLF & _ " @endforelse" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @unless($this->hidePagination)" & @CRLF & _ " <div class="rounded-lg rounded-t-none max-w-screen border-b border-gray-200 bg-white">" & @CRLF & _ " <div class="p-2 sm:flex items-center justify-between">" & @CRLF & _ " {{-- check if there is any data --}}" & @CRLF & _ " @if(count($this->results))" & @CRLF & _ " <div class="px-8 my-2 sm:my-0 flex items-center">" & @CRLF & _ " <select name="perPage" class="custom-select custom-select-sm form-control form-control-sm form-select block w-full leading-6 focus:outline-none" wire:model="perPage">" & @CRLF & _ " @foreach(config('livewire-datatables.per_page_options', [ 10, 25, 50, 100 ]) as $per_page_option)" & @CRLF & _ " <option value="{{ $per_page_option }}">{{ $per_page_option }}</option>" & @CRLF & _ " @endforeach" & @CRLF & _ " <option value="99999999">{{__('All')}}</option>" & @CRLF & _ " </select>" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " <div class="my-4 sm:my-0">" & @CRLF & _ " <div class="lg:hidden">" & @CRLF & _ " <span class="space-x-2">{{ $this->results->links('datatables::tailwind-simple-pagination') }}</span>" & @CRLF & _ " </div>" & @CRLF & _ " <div class="hidden lg:flex justify-center">" & @CRLF & _ " <span>{{ $this->results->links('datatables::tailwind-pagination') }}</span>" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ " <div class="flex justify-end text-gray-600">" & @CRLF & _ " {{__('Results')}} {{ $this->results->firstItem() }} - {{ $this->results->lastItem() }} {{__('of')}}" & @CRLF & _ " {{ $this->results->total() }}" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ " </div>" & @CRLF & _ " </div>" & @CRLF & _ " @if($afterTableSlot)" & @CRLF & _ " <div class="mt-8">" & @CRLF & _ " @include($afterTableSlot)" & @CRLF & _ " </div>" & @CRLF & _ " @endif" & @CRLF & _ "</div>" & @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