-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathregex.html
More file actions
215 lines (161 loc) · 7 KB
/
regex.html
File metadata and controls
215 lines (161 loc) · 7 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Mar 18 08:51:05 2024 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>regex</title>
</head>
<body>
<h1 align="center">regex</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNTAX">SYNTAX</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#USAGE">USAGE</a><br>
<a href="#EXAMPLES">EXAMPLES</a><br>
<a href="#COPYRIGHT">COPYRIGHT</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">regexsearch,
regexsubstitute, regexextract − RWP*Load Simulator
regular expression statements</p>
<h2>SYNTAX
<a name="SYNTAX"></a>
</h2>
<pre style="margin-left:11%; margin-top: 1em">regexsearch ::=
<b> regex</b> concatenation<b> ,</b> concatenation<b> ,</b> identifier {<b> ,</b> identifier }
regexsubstitute ::=
<b> regexsub</b> concatenation<b> ,</b> concatenation<b> ,</b> concatenation<b> ,</b> identifier
|<b> regexsubg</b> concatenation<b> ,</b> concatenation<b> ,</b> concatenation<b> ,</b> identifier
regexextract ::=
<b> regexextract</b> concatenation<b> ,</b> concatenation<b> ,</b> identifier {<b> ,</b> identifier }</pre>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The regex
search statement searches for one or more appearances of a
regular expression in a concatenation, and saves matches
into variables.</p>
<p style="margin-left:11%; margin-top: 1em">The regex
substitute statements search for a regular expression in a
concatenation and replaces the first or all occurrences of
it by a replacement concatenation returning the result in a
variable.</p>
<p style="margin-left:11%; margin-top: 1em">The regex
extract statement searches for a regular expression in a
concatenation and extracts parenthesized sub-expressions
into variables.</p>
<p style="margin-left:11%; margin-top: 1em">These functions
all use <i>extended</i> regular expressions (modern in POSIX
terminology) and are implemented using regex(3) with cflags
set to REG_EXTENED at the call to regcomp(3). The first
statement is similar to egrep(1), the two substitute
statements are similar to the s command in sed(1).</p>
<h2>USAGE
<a name="USAGE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>regex r,s,v1
[,v2 ...]</b></p>
<p style="margin-left:17%;">The value, r, must be an
extended regular expression, which will be used to search s.
The first, second, etc occurrence of the regular expression
r in s will be saved in the identified variables. If there
are no matches, the first (and compulsory) variable will be
null. If there are fewer matches than variables, those not
filled will be null. The variables can be of type integer,
double or string, and even a variable of string will be null
if no match is assigned to it.</p>
<p style="margin-left:11%; margin-top: 1em"><b>regexsub
r,s,n,v</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>regexsubg
r,s,n,v</b></p>
<p style="margin-left:17%;">These statements require three
concatenations that are string values, r, s and n, and one
identifier, v. The extended regular expression, r, will be
used to search s, in which any occurrence of r will be
substituted by n. The identifier, v, must be a string
variable and the result of the substitution will be saved in
this variable. If there is no match, the variable will be
set to null. In the replacement string, n, \N where N is a
single digit refers to the N’th parenthesized
sub-expression in the regular expression, r; see regex(3)
for details. Note that if you code n as a string constant,
the single \ must be escaped and therefore written \\. The
difference between <b>regexsub</b> and <b>regexsubg</b> is
that the former only replaces the first occurrence of r in s
by n, the latter replaces all.</p>
<p style="margin-left:11%; margin-top: 1em"><b>regexextract
r,s,v1 [,v2 ...]</b></p>
<p style="margin-left:17%;">The value, r, must be an
extended regular expression including parenthesized
sub-expression, which will be used to search s. Each
parenthesized sub-expression will be saved in the identified
variables. If there is no match, the first (and compulsory)
variable will be null. If there are fewer parenthesized
sub-expressions than variables, those not filled will be
null and a warning will be printed. The variables can be of
type integer, double or string, and even a variable of
string will be null if no match is assigned to it. If a
sub-expression that is empty or only contains white space
characters is assigned to a double or integer variable, the
variable will be set to null.</p>
<h2>EXAMPLES
<a name="EXAMPLES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The first
example shows how the <b>regex</b> statement can be used to
extract integers from a string. The output will be the
values 12 and 34.</p>
<pre style="margin-left:17%; margin-top: 1em">integer a,b;
regex "[0-9]+", "ab12cd34ef56", a,b;
printline a,b;</pre>
<p style="margin-left:11%; margin-top: 1em">When executing
this second example</p>
<pre style="margin-left:17%; margin-top: 1em">string res;
# replace all o by O
regexsubg "o", "hello world","O",res;
printline res;
# reverse two words consisting of a-z
regexsub "([a-z]+) ([a-z]+)", "hello world", "\\2 \\1",res;
printline res;</pre>
<p style="margin-left:11%; margin-top: 1em">the output will
be these two lines:</p>
<pre style="margin-left:17%; margin-top: 1em">hellO wOrld
world hello</pre>
<p style="margin-left:11%; margin-top: 1em">The last
example shows how regexextract can be used to extract two
white-space delimited words from a string and print them in
the opposite order with a - between them:</p>
<pre style="margin-left:17%; margin-top: 1em">string s,t;
regexextract "([a-z]+)[ \t]+([a-z]+)", "!hello world42", s,t;
printline t "-" s;</pre>
<p style="margin-left:11%; margin-top: 1em">which will
produce this output:</p>
<p style="margin-left:17%; margin-top: 1em">world-hello</p>
<h2>COPYRIGHT
<a name="COPYRIGHT"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Copyright
© 2023 Oracle Corporation <br>
Licensed under the Universal Permissive License v 1.0 as
shown at https://oss.oracle.com/licenses/upl</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><a href="statement.html">statement(1rwl)</a>,
<a href="variable.html">variable(1rwl)</a>, <a href="concatenation.html">concatenation(1rwl)</a></p>
<hr>
</body>
</html>