The POSIX-Basic regular expression syntax is used by the Unix utility <codeclass="computeroutput"><spanclass="identifier">sed</span></code>, and variations are used by <codeclass="computeroutput"><spanclass="identifier">grep</span></code> and <codeclass="computeroutput"><spanclass="identifier">emacs</span></code>.
You can construct POSIX basic regular expressions in Boost.Regex by passing
the flag <codeclass="computeroutput"><spanclass="identifier">basic</span></code> to the regex
constructor (see <ahref="../ref/syntax_option_type.html"title="syntax_option_type"><codeclass="computeroutput"><spanclass="identifier">syntax_option_type</span></code></a>), for example:
</p>
<preclass="programlisting">
<spanclass="comment">// e1 is a case sensitive POSIX-Basic expression:
Any atom (a single character, a marked sub-expression, or a character class)
can be repeated with the * operator.
</p>
<p>
For example <codeclass="computeroutput"><spanclass="identifier">a</span><spanclass="special">*</span></code>
will match any number of letter a's repeated zero or more times (an atom
repeated zero times matches an empty string), so the expression <codeclass="computeroutput"><spanclass="identifier">a</span><spanclass="special">*</span><spanclass="identifier">b</span></code>
will match any of the following:
</p>
<preclass="programlisting">b
ab
aaaaaaaab
</pre>
<p>
An atom can also be repeated with a bounded repeat:
<codeclass="computeroutput"><spanclass="identifier">a</span><spanclass="special">\{</span><spanclass="identifier">n</span><spanclass="special">,</span><spanclass="identifier">m</span><spanclass="special">\}</span></code> Matches 'a' repeated between n and m times
inclusive.
</p>
<p>
For example:
</p>
<preclass="programlisting">^a{2,3}$</pre>
<p>
Will match either of:
</p>
<preclass="programlisting">aa
aaa
</pre>
<p>
But neither of:
</p>
<preclass="programlisting">a
aaaa
</pre>
<p>
It is an error to use a repeat operator, if the preceding construct can not
be repeated, for example:
</p>
<preclass="programlisting">a(*)</pre>
<p>
Will raise an error, as there is nothing for the * operator to be applied
For example <codeclass="computeroutput"><spanclass="special">[</span><spanclass="identifier">abc</span><spanclass="special">]</span></code>, will match any of the characters 'a', 'b',
For example <codeclass="computeroutput"><spanclass="special">[</span><spanclass="identifier">a</span><spanclass="special">-</span><spanclass="identifier">c</span><spanclass="special">]</span></code>
will match any single character in the range 'a' to 'c'. By default, for
POSIX-Basic regular expressions, a character <spanclass="emphasis"><em>x</em></span> is within
the range <spanclass="emphasis"><em>y</em></span> to <spanclass="emphasis"><em>z</em></span>, if it collates
within that range; this results in locale specific behavior. This behavior
can be turned off by unsetting the <codeclass="computeroutput"><spanclass="identifier">collate</span></code>
option flag when constructing the regular expression - in which case whether
a character appears within a range is determined by comparing the code points
If the bracket-expression begins with the ^ character, then it matches the
complement of the characters it contains, for example <codeclass="computeroutput"><spanclass="special">[^</span><spanclass="identifier">a</span><spanclass="special">-</span><spanclass="identifier">c</span><spanclass="special">]</span></code> matches any character that is not in the
An expression of the form <codeclass="computeroutput"><spanclass="special">[[:</span><spanclass="identifier">name</span><spanclass="special">:]]</span></code>
matches the named character class "name", for example <codeclass="computeroutput"><spanclass="special">[[:</span><spanclass="identifier">lower</span><spanclass="special">:]]</span></code> matches any lower case character. See
<ahref="character_classes.html"title="Character Class Names">character class names</a>.
An expression of the form <codeclass="computeroutput"><spanclass="special">[[.</span><spanclass="identifier">col</span><spanclass="special">.]</span></code> matches
the collating element <spanclass="emphasis"><em>col</em></span>. A collating element is any
single character, or any sequence of characters that collates as a single
unit. Collating elements may also be used as the end point of a range, for
matches the character sequence "ae", plus any single character
in the rangle "ae"-c, assuming that "ae" is treated as
a single collating element in the current locale.
</p>
<p>
Collating elements may be used in place of escapes (which are not normally
allowed inside character sets), for example <codeclass="computeroutput"><spanclass="special">[[.^.]</span><spanclass="identifier">abc</span><spanclass="special">]</span></code> would
match either one of the characters 'abc^'.
</p>
<p>
As an extension, a collating element may also be specified via its symbolic
name, for example:
</p>
<preclass="programlisting">[[.NUL.]]</pre>
<p>
matches a 'NUL' character. See <ahref="collating_names.html"title="Collating Names">collating
An expression of theform <codeclass="computeroutput"><spanclass="special">[[=</span><spanclass="identifier">col</span><spanclass="special">=]]</span></code>,
matches any character or collating element whose primary sort key is the
same as that for collating element <spanclass="emphasis"><em>col</em></span>, as with collating
elements the name <spanclass="emphasis"><em>col</em></span> may be a <ahref="collating_names.html"title="Collating Names">collating
symbolic name</a>. A primary sort key is one that ignores case, accentation,
or locale-specific tailorings; so for example <codeclass="computeroutput"><spanclass="special">[[=</span><spanclass="identifier">a</span><spanclass="special">=]]</span></code> matches
any of the characters: a, <20>, <20>, <20>, <20>, <20>, <20>, A, <20>, <20>, <20>, <20>, <20> and <20>. Unfortunately implementation
of this is reliant on the platform's collation and localisation support;
this feature can not be relied upon to work portably across all platforms,
When an expression is compiled with the flag <codeclass="computeroutput"><spanclass="identifier">grep</span></code>
set, then the expression is treated as a newline separated list of <ahref="basic_syntax.html#boost_regex.posix_basic">POSIX-Basic expressions</a>, a match
is found if any of the expressions in the list match, for example:
There are a <ahref="../ref/syntax_option_type/syntax_option_type_basic.html"title="Options for POSIX Basic Regular Expressions">variety
of flags</a> that may be combined with the <codeclass="computeroutput"><spanclass="identifier">basic</span></code>
and <codeclass="computeroutput"><spanclass="identifier">grep</span></code> options when constructing
the regular expression, in particular note that the <ahref="../ref/syntax_option_type/syntax_option_type_basic.html"title="Options for POSIX Basic Regular Expressions"><codeclass="computeroutput"><spanclass="identifier">newline_alt</span></code>, <codeclass="computeroutput"><spanclass="identifier">no_char_classes</span></code>,
and <codeclass="computeroutput"><spanclass="identifier">bk_plus_vbar</span></code></a> options
all alter the syntax, while the <ahref="../ref/syntax_option_type/syntax_option_type_basic.html"title="Options for POSIX Basic Regular Expressions"><codeclass="computeroutput"><spanclass="identifier">collate</span></code> and <codeclass="computeroutput"><spanclass="identifier">icase</span></code>
options</a> modify how the case and locale sensitivity are to be applied.