• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>Chapter 46. Boost.Xpressive</title>
6<link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)">
10<link rel="prev" href="variant/refs.html" title="References">
11<link rel="next" href="xpressive/user_s_guide.html" title="User's Guide">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
16<td align="center"><a href="../../index.html">Home</a></td>
17<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="variant/refs.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="xpressive/user_s_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="chapter">
27<div class="titlepage"><div>
28<div><h2 class="title">
29<a name="xpressive"></a>Chapter 46. Boost.Xpressive</h2></div>
30<div><div class="author"><h3 class="author">
31<span class="firstname">Eric</span> <span class="surname">Niebler</span>
32</h3></div></div>
33<div><p class="copyright">Copyright © 2007 Eric Niebler</p></div>
34<div><div class="legalnotice">
35<a name="xpressive.legal"></a><p>
36        Distributed under the Boost Software License, Version 1.0. (See accompanying
37        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
38      </p>
39</div></div>
40</div></div>
41<div class="toc">
42<p><b>Table of Contents</b></p>
43<dl class="toc">
44<dt><span class="section"><a href="xpressive.html#boost_xpressive.preface">Preface</a></span></dt>
45<dt><span class="section"><a href="xpressive/user_s_guide.html">User's Guide</a></span></dt>
46<dd><dl>
47<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.introduction">Introduction</a></span></dt>
48<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.installing_xpressive">Installing
49      xpressive</a></span></dt>
50<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.quick_start">Quick Start</a></span></dt>
51<dt><span class="section"><a href="xpressive/user_s_guide.html#xpressive.user_s_guide.creating_a_regex_object">Creating
52      a Regex Object</a></span></dt>
53<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.matching_and_searching">Matching
54      and Searching</a></span></dt>
55<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.accessing_results">Accessing
56      Results</a></span></dt>
57<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.string_substitutions">String
58      Substitutions</a></span></dt>
59<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.string_splitting_and_tokenization">String
60      Splitting and Tokenization</a></span></dt>
61<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.named_captures">Named Captures</a></span></dt>
62<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.grammars_and_nested_matches">Grammars
63      and Nested Matches</a></span></dt>
64<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.semantic_actions_and_user_defined_assertions">Semantic
65      Actions and User-Defined Assertions</a></span></dt>
66<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.symbol_tables_and_attributes">Symbol
67      Tables and Attributes</a></span></dt>
68<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.localization_and_regex_traits">Localization
69      and Regex Traits</a></span></dt>
70<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.tips_n_tricks">Tips 'N Tricks</a></span></dt>
71<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.concepts">Concepts</a></span></dt>
72<dt><span class="section"><a href="xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples">Examples</a></span></dt>
73</dl></dd>
74<dt><span class="section"><a href="xpressive/reference.html">Reference</a></span></dt>
75<dd><dl>
76<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.basic_regex_hpp">Header &lt;boost/xpressive/basic_regex.hpp&gt;</a></span></dt>
77<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.match_results_hpp">Header &lt;boost/xpressive/match_results.hpp&gt;</a></span></dt>
78<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_actions_hpp">Header &lt;boost/xpressive/regex_actions.hpp&gt;</a></span></dt>
79<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_algorithms_hpp">Header &lt;boost/xpressive/regex_algorithms.hpp&gt;</a></span></dt>
80<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_compiler_hpp">Header &lt;boost/xpressive/regex_compiler.hpp&gt;</a></span></dt>
81<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_constants_hpp">Header &lt;boost/xpressive/regex_constants.hpp&gt;</a></span></dt>
82<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_error_hpp">Header &lt;boost/xpressive/regex_error.hpp&gt;</a></span></dt>
83<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_iterator_hpp">Header &lt;boost/xpressive/regex_iterator.hpp&gt;</a></span></dt>
84<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_primitives_hpp">Header &lt;boost/xpressive/regex_primitives.hpp&gt;</a></span></dt>
85<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_token_iterator_hpp">Header &lt;boost/xpressive/regex_token_iterator.hpp&gt;</a></span></dt>
86<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.regex_traits_hpp">Header &lt;boost/xpressive/regex_traits.hpp&gt;</a></span></dt>
87<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.sub_match_hpp">Header &lt;boost/xpressive/sub_match.hpp&gt;</a></span></dt>
88<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.c_regex_traits_hpp">Header &lt;boost/xpressive/traits/c_regex_traits.hpp&gt;</a></span></dt>
89<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.cpp_regex_traits_hpp">Header &lt;boost/xpressive/traits/cpp_regex_traits.hpp&gt;</a></span></dt>
90<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.traits.null_regex_traits_hpp">Header &lt;boost/xpressive/traits/null_regex_traits.hpp&gt;</a></span></dt>
91<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_hpp">Header &lt;boost/xpressive/xpressive.hpp&gt;</a></span></dt>
92<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_dynamic_hpp">Header &lt;boost/xpressive/xpressive_dynamic.hpp&gt;</a></span></dt>
93<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_fwd_hpp">Header &lt;boost/xpressive/xpressive_fwd.hpp&gt;</a></span></dt>
94<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_static_hpp">Header &lt;boost/xpressive/xpressive_static.hpp&gt;</a></span></dt>
95<dt><span class="section"><a href="xpressive/reference.html#header.boost.xpressive.xpressive_typeof_hpp">Header &lt;boost/xpressive/xpressive_typeof.hpp&gt;</a></span></dt>
96</dl></dd>
97<dt><span class="section"><a href="boost_xpressive/acknowledgments.html">Acknowledgments</a></span></dt>
98<dt><span class="section"><a href="xpressive/appendices.html">Appendices</a></span></dt>
99<dd><dl>
100<dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.appendix_1__history">Appendix
101      1: History</a></span></dt>
102<dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.appendix_2__not_yet_implemented">Appendix
103      2: Not Yet Implemented</a></span></dt>
104<dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.appendix_3__differences_from_boost_regex">Appendix
105      3: Differences from Boost.Regex</a></span></dt>
106<dt><span class="section"><a href="xpressive/appendices.html#boost_xpressive.appendices.perf">Appendix 4: Performance
107      Comparison</a></span></dt>
108<dt><span class="section"><a href="xpressive/appendices.html#xpressive.appendices.appendix_5__implementation_notes">Appendix
109      5: Implementation Notes</a></span></dt>
110</dl></dd>
111</dl>
112</div>
113<div class="section">
114<div class="titlepage"><div><div><h2 class="title" style="clear: both">
115<a name="boost_xpressive.preface"></a><a class="link" href="xpressive.html#boost_xpressive.preface" title="Preface">Preface</a>
116</h2></div></div></div>
117<div class="blockquote"><blockquote class="blockquote"><p>
118        <span class="emphasis"><em>Wife:</em></span> New Shimmer is a floor wax!<br> <span class="emphasis"><em>Husband:</em></span>
119        No, new Shimmer is a dessert topping!<br> <span class="emphasis"><em>Wife:</em></span> It's
120        a floor wax!<br> <span class="emphasis"><em>Husband:</em></span> It's a dessert topping!<br>
121        <span class="emphasis"><em>Wife:</em></span> It's a floor wax, I'm telling you!<br> <span class="emphasis"><em>Husband:</em></span>
122        It's a dessert topping, you cow!<br> <span class="emphasis"><em>Announcer:</em></span> Hey,
123        hey, hey, calm down, you two. New Shimmer is both a floor wax <span class="emphasis"><em>and</em></span>
124        a dessert topping!
125      </p></blockquote></div>
126<div class="blockquote"><blockquote class="blockquote"><p>
127        <span class="bold"><strong><span class="emphasis"><em>-- Saturday Night Live</em></span></strong></span>
128      </p></blockquote></div>
129<h3>
130<a name="boost_xpressive.preface.h0"></a>
131      <span class="phrase"><a name="boost_xpressive.preface.description"></a></span><a class="link" href="xpressive.html#boost_xpressive.preface.description">Description</a>
132    </h3>
133<p>
134      xpressive is an advanced, object-oriented regular expression template library
135      for C++. Regular expressions can be written as strings that are parsed at run-time,
136      or as expression templates that are parsed at compile-time. Regular expressions
137      can refer to each other and to themselves recursively, allowing you to build
138      arbitrarily complicated grammars out of them.
139    </p>
140<h3>
141<a name="boost_xpressive.preface.h1"></a>
142      <span class="phrase"><a name="boost_xpressive.preface.motivation"></a></span><a class="link" href="xpressive.html#boost_xpressive.preface.motivation">Motivation</a>
143    </h3>
144<p>
145      If you need to manipulate text in C++, you have typically had two disjoint
146      options: a regular expression engine or a parser generator. Regular expression
147      engines (like <a href="../../libs/regex" target="_top">Boost.Regex</a>) are powerful
148      and flexible; patterns are represented as strings which can be specified at
149      runtime. However, that means that syntax errors are likewise not detected until
150      runtime. Also, regular expressions are ill-suited to advanced text processing
151      tasks such as matching balanced, nested tags. Those tasks have traditionally
152      been handled by parser generators (like the <a href="http://spirit.sourceforge.net" target="_top">Spirit
153      Parser Framework</a>). These beasts are more powerful but less flexible.
154      They generally don't allow you to arbitrarily modify your grammar rules on
155      the fly. In addition, they don't have the exhaustive backtracking semantics
156      of regular expressions, which can make it more challenging to author some types
157      of patterns.
158    </p>
159<p>
160      xpressive brings these two approaches seamlessly together and occupies a unique
161      niche in the world of C++ text processing. With xpressive, you can choose to
162      use it much as you would use <a href="../../libs/regex" target="_top">Boost.Regex</a>,
163      representing regular expressions as strings. Or you can use it as you would
164      use <a href="http://spirit.sourceforge.net" target="_top">Spirit</a>, writing your
165      regexes as C++ expressions, enjoying all the benefits of an embedded language
166      dedicated to text manipulation. What's more, you can mix the two to get the
167      benefits of both, writing regular expression <span class="emphasis"><em>grammars</em></span>
168      in which some of the regular expressions are statically bound -- hard-coded
169      and syntax-checked by the compiler -- and others are dynamically bound and
170      specified at runtime. These regular expressions can refer to each other recursively,
171      matching patterns in strings that ordinary regular expressions cannot.
172    </p>
173<h3>
174<a name="boost_xpressive.preface.h2"></a>
175      <span class="phrase"><a name="boost_xpressive.preface.influences_and_related_work"></a></span><a class="link" href="xpressive.html#boost_xpressive.preface.influences_and_related_work">Influences
176      and Related Work</a>
177    </h3>
178<p>
179      The design of xpressive's interface has been strongly influenced by John Maddock's
180      <a href="../../libs/regex" target="_top">Boost.Regex</a> library and his <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1429.htm" target="_top">proposal</a>
181      to add regular expressions to the Standard Library. I also drew a great deal
182      of inspiration from Joel de Guzman's <a href="http://spirit.sourceforge.net" target="_top">Spirit
183      Parser Framework</a>, which served as the model for static xpressive. Other
184      sources of inspiration are the <a href="http://www.perl.com/pub/a/2002/06/04/apo5.html" target="_top">Perl
185      6</a> redesign and <a href="http://research.microsoft.com/projects/greta" target="_top">GRETA</a>.
186      (You can read a summary of the changes Perl 6 will bring to regex culture
187      <a href="http://dev.perl.org/perl6/doc/design/syn/S05.html" target="_top">here</a>.)
188    </p>
189</div>
190</div>
191<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
192<td align="left"><p><small>Last revised: August 11, 2020 at 15:03:11 GMT</small></p></td>
193<td align="right"><div class="copyright-footer"></div></td>
194</tr></table>
195<hr>
196<div class="spirit-nav">
197<a accesskey="p" href="variant/refs.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="xpressive/user_s_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
198</div>
199</body>
200</html>
201