• Home
  • Raw
  • Download

Lines Matching full:regex

13 code and data from within the regex. This enables programming idioms that are not possible with oth…
14 expression libraries. Of particular note is the ability for one regex to refer to another regex, al…
15 to build grammars out of regular expressions. This section describes how to embed one regex in anot…
16 and by reference, how regex objects behave when they refer to other regexes, and how to access the …
19 [h2 Embedding a Regex by Value]
21 The _basic_regex_ object has value semantics. When a regex object appears on the right-hand side in…
22 of another regex, it is as if the regex were embedded by value; that is, a copy of the nested regex
23 the enclosing regex. The inner regex is invoked by the outer regex during pattern matching. The inn…
26 Consider a text editor that has a regex-find feature with a whole-word option. You can implement th…
39 // wrap the regex in begin-word / end-word assertions
48 // wrap the regex in begin-word / end-word assertions
51 This line creates a new regex that embeds the old regex by value. Then, the new regex is assigned b…
52 the original regex. Since a copy of the old regex was made on the right-hand side, this works as yo…
53 expect: the new regex has the behavior of the old regex wrapped in begin- and end-word assertions.
55 …te Note that `re = bow >> re >> eow` does ['not] define a recursive regular expression, since regex
57 embedding a regex by reference.]
59 [h2 Embedding a Regex by Reference]
61 …want to be able to build recursive regular expressions and context-free grammars, embedding a regex
87 expressions cannot do. The `by_ref()` helper makes it possible. It allows one regex object to be em…
104 The regex `expression` defined above does something rather remarkable for a regular expression: it …
113 a cyclic grammar is to forward-declare the regex objects and embed by reference those regular expre…
115 a regex object that has not yet been initialized: the definition of `group`. In that place, we use
117 regex objects by value, since they have already been initialized and their values will not change.
124 a regex. Each regex object shares its implementation with all of its copies.]
126 [h2 Dynamic Regex Grammars]
133 You can create a named dynamic regex by prefacing your regex with `"(?$name=)"`, where
134 /name/ is the name of the regex. You can refer to a named regex from another regex with
135 `"(?$name)"`. The named regex does not need to exist yet at the time it is referenced
136 in another regex, but it must exist by the time you use the regex.
138 Below is a code fragment that uses dynamic regex grammars to implement the calculator
167 As with static regex grammars, nested regex invocations create nested
175 four regex objects refer to each other, some directly and some indirectly, some by value and some by
177 What becomes of the references? The answer is that the regex objects are internally reference count…
178 such that they keep their referenced regex objects alive as long as they need them. So passing a re…
179 object by value is never a problem, even if it refers to other regex objects that have gone out of …
182 references. If regex objects are reference counted, what happens to cycles like the one created in …
184 reference tracking code that ensures that even cyclic regex grammars are cleaned up when the last e…
185 reference goes away. So don't worry about it. Create cyclic grammars, pass your regex objects aroun…
190 Nested regular expressions raise the issue of sub-match scoping. If both the inner and outer regex
191 to and read from the same sub-match vector, chaos would ensue. The inner regex would stomp on the
192 sub-matches written by the outer regex. For example, what does this do?
197 The author probably didn't intend for the inner regex to overwrite the sub-match written by the out…
198 regex. The problem is particularly acute when the inner regex is accepted from the user as input. T…
199 author has no way of knowing whether the inner regex will stomp the sub-match vector or not. This is
202 Instead, what actually happens is that each invocation of a nested regex gets its own scope. Sub-ma…
203 belong to that scope. That is, each nested regex invocation gets its own copy of the sub-match vect…
204 play with, so there is no way for an inner regex to stomp on the sub-matches of an outer regex. So,…
205 example, the regex `outer` defined above would match `"ABBA"`, as it should.
214 the nested regex objects matched.
216 Take as an example the regex for balanced, nested parentheses we saw earlier:
255 Sometimes a regex will have several nested regex objects, and you want to know which result corresp…
256 to which regex object. That's where `basic_regex<>::regex_id()` and `match_results<>::regex_id()`
257 come in handy. When iterating over the nested results, you can compare the regex id from the result…
258 the id of the regex object you're interested in.
261 results that correspond to a certain nested regex. It is called `regex_id_filter_predicate`, and it…
280 // iterate over only the results from the name regex
289 // iterate over only the results from the integer regex
300 corresponding to a particular nested regex. This program displays the following: