summaryrefslogtreecommitdiff
path: root/tools/build/doc/src/regex.xml
blob: 234c6eae4c13e2d44dab8d04acc1e378a30c4b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">

<section id="bbv2.reference.modules.regex">

  <title>regex</title>
  <indexterm>
    <primary>regex</primary>
    <secondary>module</secondary>
  </indexterm>

  <para>
    Contains rules for string processing using regular expressions.
  </para>

  <itemizedlist>

    <listitem><para>
      <code language="jam">"x*"</code> matches the pattern
      <code language="jam">"x"</code> zero or more times.
    </para></listitem>
    
    <listitem><para>
      <code language="jam">"x+"</code> matches <code language="jam">"x"</code>
      one or more times.
    </para></listitem>
    
    <listitem><para>
      <code language="jam">"x?"</code> matches <code language="jam">"x"</code>
      zero or one time.
    </para></listitem>
    
    <listitem><para>
      <code language="jam">"[abcd]"</code> matches any of the characters,
      <code language="jam">"a"</code>, <code language="jam">"b"</code>,
      <code language="jam">"c"</code>, and <code language="jam">"d"</code>.
      A character range such as <code language="jam">"[a-z]"</code> matches
      any character between <code language="jam">"a"</code> and
      <code language="jam">"z"</code>.  <code language="jam">"[^abc]"</code>
      matches any character which is not <code language="jam">"a"</code>,
      <code language="jam">"b"</code>, or <code language="jam">"c"</code>.
    </para></listitem>

    <listitem><para>
      <code language="jam">"x|y"</code> matches either pattern
      <code language="jam">"x"</code> or pattern <code language="jam">"y"</code>
    </para></listitem>
    
    <listitem><para>
      <code language="jam">(x)</code> matches <code language="jam">"x"</code>
      and captures it.
    </para></listitem>
    
    <listitem><para>
      <code language="jam">"^"</code> matches the beginning of the string.
    </para></listitem>
    
    <listitem><para>
      <code language="jam">"$"</code> matches the end of the string.
    </para></listitem>

    <listitem><para>
      "\&lt;" matches the beginning of a word.
    </para></listitem>

    <listitem><para>
      "\&gt;" matches the end of a word.
    </para></listitem>
    
  </itemizedlist>

  <orderedlist>

    <listitem id="bbv2.reference.modules.regex.split">
      <indexterm zone="bbv2.reference.modules.regex.split">
        <primary>split</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule split ( string separator )</code>
      <para>Returns a list of the following substrings:
      <orderedlist>
        <listitem><para>from beginning till the first occurrence of
        <code language="jam">separator</code> or till the end,
        </para></listitem>
        <listitem><para>between each occurrence of
        <code language="jam">separator</code> and the next occurrence,
        </para></listitem>
        <listitem><para>from the last occurrence of
        <code language="jam">separator</code> till the end.
        </para></listitem>
      </orderedlist>
      If no separator is present, the result will contain only one element.
      </para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.split-list">
      <indexterm zone="bbv2.reference.modules.regex.split-list">
        <primary>split-list</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule split-list ( list * : separator )</code>
      <para>Returns the concatenated results of applying
      <link linkend="bbv2.reference.modules.regex.split">regex.split</link>
      to every element of the list using the separator pattern.</para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.match">
      <indexterm zone="bbv2.reference.modules.regex.match">
        <primary>match</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule match ( pattern : string : indices * )</code>
      <para>Match <code language="jam">string</code> against
      <code language="jam">pattern</code>, and return the elements
      indicated by <code language="jam">indices</code>.
      </para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.transform">
      <indexterm zone="bbv2.reference.modules.regex.transform">
        <primary>transform</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule transform ( list * : pattern : indices * )</code>
      <para>Matches all elements of <code language="jam">list</code> against
      the <code language="jam">pattern</code> and returns a list of elements
      indicated by <code language="jam">indices</code> of all successful
      matches. If <code language="jam">indices</code> is omitted returns a list
      of first parenthesized groups of all successful matches.</para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.escape">
      <indexterm zone="bbv2.reference.modules.regex.escape">
        <primary>escape</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule escape ( string : symbols : escape-symbol )</code>
      <para>Escapes all of the characters in <code language="jam">symbols</code>
      using the escape symbol <code language="jam">escape-symbol</code> for
      the given string, and returns the escaped string.</para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.replace">
      <indexterm zone="bbv2.reference.modules.regex.replace">
        <primary>replace</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule replace ( string match replacement )</code>
      <para>Replaces occurrences of a match string in a given string and
      returns the new string. The match string can be a regex expression.</para>
    </listitem>

    <listitem id="bbv2.reference.modules.regex.replace-list">
      <indexterm zone="bbv2.reference.modules.regex.replace-list">
        <primary>replace-list</primary>
        <secondary>regex</secondary>
      </indexterm>
      <code language="jam">rule replace-list ( list * : match : replacement )</code>
      <para>Replaces occurrences of a match string in a given list of strings
      and returns a list of new strings. The match string can be a regex
      expression.
      </para>
    </listitem>

  </orderedlist>
  
  <para>See also: <link linkend="jam.language.rules.builtins.utility._match__">MATCH</link></para>

</section>