Files
OBIJupyterHub/jupyterhub_volumes/web/obidoc/docs/patterns/regular/index.html
Eric Coissac 30b7175702 Make cleaning
2025-11-17 14:18:13 +01:00

2130 lines
35 KiB
HTML

<!DOCTYPE html>
<html lang="en-us" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="
Regular Expressions
#
Regular expressions are a powerful tool for describing patterns in text. They are used in several OBITools
like
obigrep
,
obiannotate
or
obiscript
.
Single characters
#
Pattern
Description
.
any character, possibly including newline (flag s=true)
[xyz]
character class
[^xyz]
negated character class
[[:alpha:]]
ASCII character class
[[:^alpha:]]
negated ASCII character class
Composites
#
Pattern
Description
xy
x followed by y
x|y
x or y (prefer x)
Repetitions
#
Pattern
Description
x*
zero or more x, prefer more
x&#43;
one or more x, prefer more
x?
zero or one x, prefer one
x{n,m}
n or n&#43;1 or &hellip; or m x, prefer more
x{n,}
n or more x, prefer more
x{n}
exactly n x
x*?
zero or more x, prefer fewer
x&#43;?
one or more x, prefer fewer
x??
zero or one x, prefer zero
x{n,m}?
n or n&#43;1 or &hellip; or m x, prefer fewer
x{n,}?
n or more x, prefer fewer
x{n}?
exactly n x
Grouping
#
Pattern
Description
(re)
numbered capturing group (submatch)
(?P&lt;name&gt;re)
named &amp; numbered capturing group (submatch)
(?&lt;name&gt;re)
named &amp; numbered capturing group (submatch)
(?:re)
non-capturing group
(?flags)
set flags within current group; non-capturing
(?flags:re)
set flags during re; non-capturing
Character classes
#
Pattern
Description
[\d]
digits (== \d)
[^\d]
not digits (== \D)
[\D]
not digits (== \D)
[^\D]
not not digits (== \d)
[[:name:]]
named ASCII class inside character class (== [:name:])
[^[:name:]]
named ASCII class inside negated character class (== [:^name:])
[\p{Name}]
named Unicode property inside character class (== \p{Name})
[^\p{Name}]
named Unicode property inside negated character class (== \P{Name})
Named character classes
#
Pattern
Description
[[:alnum:]]
alphanumeric (== [0-9A-Za-z])
[[:alpha:]]
alphabetic (== [A-Za-z])
[[:ascii:]]
ASCII (== [\x00-\x7F])
[[:blank:]]
blank (== [\t ])
[[:cntrl:]]
control (== [\x00-\x1F\x7F])
[[:digit:]]
digits (== [0-9])
[[:graph:]]
graphical (== [!-~] == [A-Za-z0-9!&quot;#$%&amp;&#39;()*&#43;,\-./:;&lt;=&gt;?@[\\\]^_`{|}~])
[[:lower:]]
lower case (== [a-z])
[[:print:]]
printable (== [ -~] == [[:graph:]])
[[:punct:]]
punctuation (== [!-/:-@[-\`{-~])
[[:space:]]
whitespace (== [\t\n\v\f\r ])
[[:upper:]]
upper case (== [A-Z])
[[:word:]]
word characters (== [0-9A-Za-z_])
[[:xdigit:]]
hex digit (== [0-9A-Fa-f])
">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#ffffff">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#343a40">
<meta name="color-scheme" content="light dark"><meta property="og:url" content="http://metabar:8888/obidoc/docs/patterns/regular/">
<meta property="og:site_name" content="OBITools4 documentation">
<meta property="og:title" content="Regular Expressions">
<meta property="og:description" content="Regular Expressions # Regular expressions are a powerful tool for describing patterns in text. They are used in several OBITools like obigrep , obiannotate or obiscript .
Single characters # Pattern Description . any character, possibly including newline (flag s=true) [xyz] character class [^xyz] negated character class [[:alpha:]] ASCII character class [[:^alpha:]] negated ASCII character class Composites # Pattern Description xy x followed by y x|y x or y (prefer x) Repetitions # Pattern Description x* zero or more x, prefer more x&#43; one or more x, prefer more x? zero or one x, prefer one x{n,m} n or n&#43;1 or … or m x, prefer more x{n,} n or more x, prefer more x{n} exactly n x x*? zero or more x, prefer fewer x&#43;? one or more x, prefer fewer x?? zero or one x, prefer zero x{n,m}? n or n&#43;1 or … or m x, prefer fewer x{n,}? n or more x, prefer fewer x{n}? exactly n x Grouping # Pattern Description (re) numbered capturing group (submatch) (?P&lt;name&gt;re) named &amp; numbered capturing group (submatch) (?&lt;name&gt;re) named &amp; numbered capturing group (submatch) (?:re) non-capturing group (?flags) set flags within current group; non-capturing (?flags:re) set flags during re; non-capturing Character classes # Pattern Description [\d] digits (== \d) [^\d] not digits (== \D) [\D] not digits (== \D) [^\D] not not digits (== \d) [[:name:]] named ASCII class inside character class (== [:name:]) [^[:name:]] named ASCII class inside negated character class (== [:^name:]) [\p{Name}] named Unicode property inside character class (== \p{Name}) [^\p{Name}] named Unicode property inside negated character class (== \P{Name}) Named character classes # Pattern Description [[:alnum:]] alphanumeric (== [0-9A-Za-z]) [[:alpha:]] alphabetic (== [A-Za-z]) [[:ascii:]] ASCII (== [\x00-\x7F]) [[:blank:]] blank (== [\t ]) [[:cntrl:]] control (== [\x00-\x1F\x7F]) [[:digit:]] digits (== [0-9]) [[:graph:]] graphical (== [!-~] == [A-Za-z0-9!&#34;#$%&amp;&#39;()*&#43;,\-./:;&lt;=&gt;?@[\\\]^_`{|}~]) [[:lower:]] lower case (== [a-z]) [[:print:]] printable (== [ -~] == [[:graph:]]) [[:punct:]] punctuation (== [!-/:-@[-\`{-~]) [[:space:]] whitespace (== [\t\n\v\f\r ]) [[:upper:]] upper case (== [A-Z]) [[:word:]] word characters (== [0-9A-Za-z_]) [[:xdigit:]] hex digit (== [0-9A-Fa-f])">
<meta property="og:locale" content="en_us">
<meta property="og:type" content="article">
<meta property="article:section" content="docs">
<title>Regular Expressions | OBITools4 documentation</title>
<link rel="icon" href="/obidoc/favicon.png" >
<link rel="manifest" href="/obidoc/manifest.json">
<link rel="canonical" href="http://metabar:8888/obidoc/docs/patterns/regular/">
<link rel="stylesheet" href="/obidoc/book.min.5fd7b8e2d1c0ae15da279c52ff32731130386f71b58f011468f20d0056fe6b78.css" integrity="sha256-X9e44tHArhXaJ5xS/zJzETA4b3G1jwEUaPINAFb&#43;a3g=" crossorigin="anonymous">
<script defer src="/obidoc/fuse.min.js"></script>
<script defer src="/obidoc/en.search.min.4da51bdd2d833922fdbc0e19df517221387fc625ffb68ee140d605b3c5b68058.js" integrity="sha256-TaUb3S2DOSL9vA4Z31FyITh/xiX/to7hQNYFs8W2gFg=" crossorigin="anonymous"></script>
<script defer src="/obidoc/sw.min.32af8eafce4180aa1c5dea66d99fb26ba9043ea7c7a4c706138c91d9051b285e.js" integrity="sha256-Mq&#43;Or85BgKocXepm2Z&#43;ya6kEPqfHpMcGE4yR2QUbKF4=" crossorigin="anonymous"></script>
<!--
Made with Book Theme
https://github.com/alex-shpak/hugo-book
-->
<link rel="stylesheet" type="text/css" href="http://metabar:8888/obidoc/hugo-cite.css" />
</head>
<body dir="ltr">
<input type="checkbox" class="hidden toggle" id="menu-control" />
<input type="checkbox" class="hidden toggle" id="toc-control" />
<main class="container flex">
<aside class="book-menu">
<div class="book-menu-content">
<nav>
<h2 class="book-brand">
<a class="flex align-center" href="/obidoc/"><img src="/obidoc/obitools_logo.jpg" alt="Logo" class="book-icon" /><span>OBITools4 documentation</span>
</a>
</h2>
<div class="book-search hidden">
<input type="text" id="book-search-input" placeholder="Search" aria-label="Search" maxlength="64" data-hotkeys="s/" />
<div class="book-search-spinner hidden"></div>
<ul id="book-search-results"></ul>
</div>
<script>document.querySelector(".book-search").classList.remove("hidden")</script>
<ul>
<li>
<span>Docs</span>
<ul>
<li>
<a href="/obidoc/docs/about/" class="">About</a>
</li>
<li>
<a href="/obidoc/docs/installation/" class="">Installation</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/principles/" class="">General operating principles</a>
<ul>
</ul>
</li>
<li>
<input type="checkbox" id="section-08756b4c1f14be6ee584ece005b9f621" class="toggle" />
<label for="section-08756b4c1f14be6ee584ece005b9f621" class="flex justify-between">
<a role="button" class="">File formats</a>
</label>
<ul>
<li>
<input type="checkbox" id="section-933c2e64b905b84e22aa5273cea2d0bd" class="toggle" />
<label for="section-933c2e64b905b84e22aa5273cea2d0bd" class="flex justify-between">
<a role="button" class="">Sequence file formats</a>
</label>
<ul>
<li>
<a href="/obidoc/formats/fasta/" class="">FASTA file format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/formats/fastq/" class="">FASTQ file format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/formats/genbank/" class="">GenBank Flat File format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/formats/embl/" class="">EMBL Flat File format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/file_format/sequence_files/csv/" class="">CSV format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/formats/json/" class="">JSON format</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/file_format/sequence_files/annotations/" class="">Annotation of sequences</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-0258ae1c222f9a38cc1b75254c93b0f4" class="toggle" />
<label for="section-0258ae1c222f9a38cc1b75254c93b0f4" class="flex justify-between">
<a role="button" class="">Taxonomy file formats</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/file_format/taxonomy_file/csv_taxdump/" class="">CSV formatted taxdump</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/file_format/taxonomy_file/ncbi_taxdump/" class="">NCBI taxdump</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<a href="/obidoc/formats/csv/" class="">The CSV format</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-70b1e6e5ec7f3ccab643155fa50659b6" class="toggle" checked />
<label for="section-70b1e6e5ec7f3ccab643155fa50659b6" class="flex justify-between">
<a role="button" class="">Patterns</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/patterns/regular/" class="active">Regular Expressions</a>
</li>
<li>
<a href="/obidoc/docs/patterns/dnagrep/" class="">DNA Patterns</a>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-8223f464911a1fe6c655972143684e93" class="toggle" />
<label for="section-8223f464911a1fe6c655972143684e93" class="flex justify-between">
<a role="button" class="">The OBITools4 commands</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/commands/options/" class="">Shared command options</a>
<ul>
</ul>
</li>
<li>
<input type="checkbox" id="section-8921ea65523c266b128dd4263232b0fc" class="toggle" />
<label for="section-8921ea65523c266b128dd4263232b0fc" class="flex justify-between">
<a role="button" class="">Basics</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obiannotate/" class="">obiannotate</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obicomplement/" class="">obicomplement</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obiconvert/" class="">obiconvert</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obicount/" class="">obicount</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obicsv/" class="">obicsv</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obidemerge/" class="">obidemerge</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obidistribute/" class="">obidistribute</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obigrep/" class="">obigrep</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obijoin/" class="">obijoin</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obimatrix/" class="">obimatrix</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obisplit/" class="">obisplit</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obisummary/" class="">obisummary</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obiuniq/" class="">obiuniq</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-dbdf1bb5377572439394e60e08c30f50" class="toggle" />
<label for="section-dbdf1bb5377572439394e60e08c30f50" class="flex justify-between">
<a role="button" class="">Demultiplexing samples</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obimultiplex/" class="">obimultiplex</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obitagpcr/" class="">obitagpcr</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-aa98fedd067b51150db59691a8ea8edd" class="toggle" />
<label for="section-aa98fedd067b51150db59691a8ea8edd" class="flex justify-between">
<a role="button" class="">Sequence alignments</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obiclean/" class="">obiclean</a>
<ul>
</ul>
</li>
<li>
<input type="checkbox" id="section-7433746525d8c2b29b033f765c869acd" class="toggle" />
<label for="section-7433746525d8c2b29b033f765c869acd" class="flex justify-between">
<a href="/obidoc/obitools/obipairing/" class="">obipairing</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/commands/alignments/obipairing/fasta-like/" class="">The FASTA-like alignment</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/commands/alignments/obipairing/exact-alignment/" class="">Exact alignment</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obipcr/" class="">obipcr</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obirefidx/" class="">obirefidx</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obitag/" class="">obitag</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-5746f699d10490780dec8e30ab2dd3ce" class="toggle" />
<label for="section-5746f699d10490780dec8e30ab2dd3ce" class="flex justify-between">
<a role="button" class="">Taxonomy</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obitaxonomy/" class="">obitaxonomy</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-3f50c4fe7ab436a56ae92897d5444956" class="toggle" />
<label for="section-3f50c4fe7ab436a56ae92897d5444956" class="flex justify-between">
<a role="button" class="">Advanced tools</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obiscript/" class="">obiscript</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-549be3934679fcb82a232f6bd5435563" class="toggle" />
<label for="section-549be3934679fcb82a232f6bd5435563" class="flex justify-between">
<a role="button" class="">Others</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obimicrosat/" class="">obimicrosat</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-ceca4455173761e30cbc0a6dc2327167" class="toggle" />
<label for="section-ceca4455173761e30cbc0a6dc2327167" class="flex justify-between">
<a role="button" class="">Experimentals</a>
</label>
<ul>
<li>
<a href="/obidoc/obitools/obicleandb/" class="">obicleandb</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obiconsensus/" class="">obiconsensus</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/obitools/obilandmark/" class="">obilandmark</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<a href="/obidoc/docs/commands/tags/" class="">Glossary of tags</a>
</li>
</ul>
</li>
<li>
<input type="checkbox" id="section-9b1bcd52530c59dc4819b1f61c128f54" class="toggle" />
<label for="section-9b1bcd52530c59dc4819b1f61c128f54" class="flex justify-between">
<a role="button" class="">Cookbook</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/cookbook/illumina/" class="">Analysing an Illumina data set</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/cookbook/ecoprimers/" class="">Designing new barcodes</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/cookbook/local_genbank/" class="">Prepare a local copy of Genbank</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/cookbook/reference_db/" class="">Build a reference database</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/cookbook/minion/" class="">Oxford Nanopore data analysis</a>
<ul>
</ul>
</li>
</ul>
</li>
<li>
<span>Programming OBITools</span>
<ul>
<li>
<a href="/obidoc/docs/programming/expression/" class="">Expression language</a>
<ul>
</ul>
</li>
<li>
<input type="checkbox" id="section-6d580829a667b5cca790b286d99a10fe" class="toggle" />
<label for="section-6d580829a667b5cca790b286d99a10fe" class="flex justify-between">
<a href="/obidoc/docs/programming/lua/" class="">Lua: for scripting OBITools</a>
</label>
<ul>
<li>
<input type="checkbox" id="section-2fb081dac812d624eea5f4268fca9e26" class="toggle" />
<label for="section-2fb081dac812d624eea5f4268fca9e26" class="flex justify-between">
<a role="button" class="">Obitools Classes</a>
</label>
<ul>
<li>
<a href="/obidoc/docs/programming/lua/obitools_classes/biosequence/" class="">BioSequence</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/programming/lua/obitools_classes/biosequenceslice/" class="">BioSequenceSlice</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/programming/lua/obitools_classes/taxonomy/" class="">Taxonomy</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/programming/lua/obitools_classes/taxon/" class="">Taxon</a>
<ul>
</ul>
</li>
<li>
<a href="/obidoc/docs/programming/lua/obitools_classes/mutex/" class="">Mutex</a>
<ul>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script>
</div>
</aside>
<div class="book-page">
<header class="book-header">
<div class="flex align-center justify-between">
<label for="menu-control">
<img src="/obidoc/svg/menu.svg" class="book-icon" alt="Menu" />
</label>
<h3>Regular Expressions</h3>
<label for="toc-control">
<img src="/obidoc/svg/toc.svg" class="book-icon" alt="Table of Contents" />
</label>
</div>
<aside class="hidden clearfix">
<nav id="TableOfContents">
<ul>
<li><a href="#regular-expressions">Regular Expressions</a>
<ul>
<li><a href="#single-characters">Single characters</a></li>
<li><a href="#composites">Composites</a></li>
<li><a href="#repetitions">Repetitions</a></li>
<li><a href="#grouping">Grouping</a></li>
<li><a href="#character-classes">Character classes</a></li>
<li><a href="#named-character-classes">Named character classes</a></li>
</ul>
</li>
</ul>
</nav>
</aside>
</header>
<article class="markdown book-article"><h1 id="regular-expressions">
Regular Expressions
<a class="anchor" href="#regular-expressions">#</a>
</h1>
<p>Regular expressions are a powerful tool for describing patterns in text. They are used in several <abbr title="A set of unix command line tools for manipulating DNA metabarcoding data">OBITools</abbr>
like <a href="http://metabar:8888/obidoc/obitools/obigrep/">
<abbr title="obigrep: filter a sequence file"><code>obigrep</code></abbr>
</a>, <a href="http://metabar:8888/obidoc/obitools/obiannotate/">
<abbr title="obiannotate: edit sequence annotations"><code>obiannotate</code></abbr>
</a> or <a href="http://metabar:8888/obidoc/obitools/obiscript/">
<abbr title="obiscript: apply a LUA script to a sequence file"><code>obiscript</code></abbr>
</a>.</p>
<h2 id="single-characters">
Single characters
<a class="anchor" href="#single-characters">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>.</code></td>
<td>any character, possibly including newline (flag s=true)</td>
</tr>
<tr>
<td><code>[xyz]</code></td>
<td>character class</td>
</tr>
<tr>
<td><code>[^xyz]</code></td>
<td>negated character class</td>
</tr>
<tr>
<td><code>[[:alpha:]]</code></td>
<td>ASCII character class</td>
</tr>
<tr>
<td><code>[[:^alpha:]]</code></td>
<td>negated ASCII character class</td>
</tr>
</tbody>
</table>
<h2 id="composites">
Composites
<a class="anchor" href="#composites">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>xy</code></td>
<td>x followed by y</td>
</tr>
<tr>
<td><code>x|y</code></td>
<td>x or y (prefer x)</td>
</tr>
</tbody>
</table>
<h2 id="repetitions">
Repetitions
<a class="anchor" href="#repetitions">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>x*</code></td>
<td>zero or more x, prefer more</td>
</tr>
<tr>
<td><code>x+</code></td>
<td>one or more x, prefer more</td>
</tr>
<tr>
<td><code>x?</code></td>
<td>zero or one x, prefer one</td>
</tr>
<tr>
<td><code>x{n,m}</code></td>
<td>n or n+1 or &hellip; or m x, prefer more</td>
</tr>
<tr>
<td><code>x{n,}</code></td>
<td>n or more x, prefer more</td>
</tr>
<tr>
<td><code>x{n}</code></td>
<td>exactly n x</td>
</tr>
<tr>
<td><code>x*?</code></td>
<td>zero or more x, prefer fewer</td>
</tr>
<tr>
<td><code>x+?</code></td>
<td>one or more x, prefer fewer</td>
</tr>
<tr>
<td><code>x??</code></td>
<td>zero or one x, prefer zero</td>
</tr>
<tr>
<td><code>x{n,m}?</code></td>
<td>n or n+1 or &hellip; or m x, prefer fewer</td>
</tr>
<tr>
<td><code>x{n,}?</code></td>
<td>n or more x, prefer fewer</td>
</tr>
<tr>
<td><code>x{n}?</code></td>
<td>exactly n x</td>
</tr>
</tbody>
</table>
<h2 id="grouping">
Grouping
<a class="anchor" href="#grouping">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>(re)</code></td>
<td>numbered capturing group (submatch)</td>
</tr>
<tr>
<td><code>(?P&lt;name&gt;re)</code></td>
<td>named &amp; numbered capturing group (submatch)</td>
</tr>
<tr>
<td><code>(?&lt;name&gt;re)</code></td>
<td>named &amp; numbered capturing group (submatch)</td>
</tr>
<tr>
<td><code>(?:re)</code></td>
<td>non-capturing group</td>
</tr>
<tr>
<td><code>(?flags)</code></td>
<td>set flags within current group; non-capturing</td>
</tr>
<tr>
<td><code>(?flags:re)</code></td>
<td>set flags during re; non-capturing</td>
</tr>
</tbody>
</table>
<h2 id="character-classes">
Character classes
<a class="anchor" href="#character-classes">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>[\d]</code></td>
<td>digits (== \d)</td>
</tr>
<tr>
<td><code>[^\d]</code></td>
<td>not digits (== \D)</td>
</tr>
<tr>
<td><code>[\D]</code></td>
<td>not digits (== \D)</td>
</tr>
<tr>
<td><code>[^\D]</code></td>
<td>not not digits (== \d)</td>
</tr>
<tr>
<td><code>[[:name:]]</code></td>
<td>named ASCII class inside character class (== [:name:])</td>
</tr>
<tr>
<td><code>[^[:name:]]</code></td>
<td>named ASCII class inside negated character class (== [:^name:])</td>
</tr>
<tr>
<td><code>[\p{Name}]</code></td>
<td>named Unicode property inside character class (== \p{Name})</td>
</tr>
<tr>
<td><code>[^\p{Name}]</code></td>
<td>named Unicode property inside negated character class (== \P{Name})</td>
</tr>
</tbody>
</table>
<h2 id="named-character-classes">
Named character classes
<a class="anchor" href="#named-character-classes">#</a>
</h2>
<table>
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>[[:alnum:]]</code></td>
<td>alphanumeric (== <code>[0-9A-Za-z]</code>)</td>
</tr>
<tr>
<td><code>[[:alpha:]]</code></td>
<td>alphabetic (== <code>[A-Za-z]</code>)</td>
</tr>
<tr>
<td><code>[[:ascii:]]</code></td>
<td>ASCII (== <code>[\x00-\x7F]</code>)</td>
</tr>
<tr>
<td><code>[[:blank:]]</code></td>
<td>blank (== <code>[\t ]</code>)</td>
</tr>
<tr>
<td><code>[[:cntrl:]]</code></td>
<td>control (== <code>[\x00-\x1F\x7F]</code>)</td>
</tr>
<tr>
<td><code>[[:digit:]]</code></td>
<td>digits (== <code>[0-9]</code>)</td>
</tr>
<tr>
<td><code>[[:graph:]]</code></td>
<td>graphical (== <code>[!-~]</code> == <code>[A-Za-z0-9!&quot;#$%&amp;'()*+,\-./:;&lt;=&gt;?@[\\\]^_`{|}~])</code></td>
</tr>
<tr>
<td><code>[[:lower:]]</code></td>
<td>lower case (== <code>[a-z]</code>)</td>
</tr>
<tr>
<td><code>[[:print:]]</code></td>
<td>printable (== <code>[ -~]</code> == <code>[[:graph:]]</code>)</td>
</tr>
<tr>
<td><code>[[:punct:]]</code></td>
<td>punctuation (== <code>[!-/:-@[-\`{-~]</code>)</td>
</tr>
<tr>
<td><code>[[:space:]]</code></td>
<td>whitespace (== <code>[\t\n\v\f\r ]</code>)</td>
</tr>
<tr>
<td><code>[[:upper:]]</code></td>
<td>upper case (== <code>[A-Z]</code>)</td>
</tr>
<tr>
<td><code>[[:word:]]</code></td>
<td>word characters (== <code>[0-9A-Za-z_]</code>)</td>
</tr>
<tr>
<td><code>[[:xdigit:]]</code></td>
<td>hex digit (== <code>[0-9A-Fa-f]</code>)</td>
</tr>
</tbody>
</table>
</article>
<footer class="book-footer">
<div class="flex flex-wrap justify-between">
</div>
<script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script>
</footer>
<div class="book-comments">
</div>
<label for="menu-control" class="hidden book-menu-overlay"></label>
</div>
<aside class="book-toc">
<div class="book-toc-content">
<nav id="TableOfContents">
<ul>
<li><a href="#regular-expressions">Regular Expressions</a>
<ul>
<li><a href="#single-characters">Single characters</a></li>
<li><a href="#composites">Composites</a></li>
<li><a href="#repetitions">Repetitions</a></li>
<li><a href="#grouping">Grouping</a></li>
<li><a href="#character-classes">Character classes</a></li>
<li><a href="#named-character-classes">Named character classes</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</aside>
</main>
</body>
</html>