Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man1 / perlreref.1
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PERLREREF 1"
132.TH PERLREREF 1 "2006-01-07" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134perlreref \- Perl Regular Expressions Reference
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137This is a quick reference to Perl's regular expressions.
138For full information see perlre and perlop, as well
139as the \*(L"\s-1SEE\s0 \s-1ALSO\s0\*(R" section in this document.
140.Sh "\s-1OPERATORS\s0"
141.IX Subsection "OPERATORS"
142.Vb 2
143\& =~ determines to which variable the regex is applied.
144\& In its absence, $_ is used.
145.Ve
146.PP
147.Vb 1
148\& $var =~ /foo/;
149.Ve
150.PP
151.Vb 3
152\& !~ determines to which variable the regex is applied,
153\& and negates the result of the match; it returns
154\& false if the match succeeds, and true if it fails.
155.Ve
156.PP
157.Vb 1
158\& $var !~ /foo/;
159.Ve
160.PP
161.Vb 2
162\& m/pattern/igmsoxc searches a string for a pattern match,
163\& applying the given options.
164.Ve
165.PP
166.Vb 7
167\& i case-Insensitive
168\& g Global - all occurrences
169\& m Multiline mode - ^ and $ match internal lines
170\& s match as a Single line - . matches \en
171\& o compile pattern Once
172\& x eXtended legibility - free whitespace and comments
173\& c don't reset pos on failed matches when using /g
174.Ve
175.PP
176.Vb 3
177\& If 'pattern' is an empty string, the last I<successfully> matched
178\& regex is used. Delimiters other than '/' may be used for both this
179\& operator and the following ones.
180.Ve
181.PP
182.Vb 3
183\& qr/pattern/imsox lets you store a regex in a variable,
184\& or pass one around. Modifiers as for m// and are stored
185\& within the regex.
186.Ve
187.PP
188.Vb 3
189\& s/pattern/replacement/igmsoxe substitutes matches of
190\& 'pattern' with 'replacement'. Modifiers as for m//
191\& with one addition:
192.Ve
193.PP
194.Vb 1
195\& e Evaluate replacement as an expression
196.Ve
197.PP
198.Vb 2
199\& 'e' may be specified multiple times. 'replacement' is interpreted
200\& as a double quoted string unless a single-quote (') is the delimiter.
201.Ve
202.PP
203.Vb 2
204\& ?pattern? is like m/pattern/ but matches only once. No alternate
205\& delimiters can be used. Must be reset with L<reset|perlfunc/reset>.
206.Ve
207.Sh "\s-1SYNTAX\s0"
208.IX Subsection "SYNTAX"
209.Vb 13
210\& \e Escapes the character immediately following it
211\& . Matches any single character except a newline (unless /s is used)
212\& ^ Matches at the beginning of the string (or line, if /m is used)
213\& $ Matches at the end of the string (or line, if /m is used)
214\& * Matches the preceding element 0 or more times
215\& + Matches the preceding element 1 or more times
216\& ? Matches the preceding element 0 or 1 times
217\& {...} Specifies a range of occurrences for the element preceding it
218\& [...] Matches any one of the characters contained within the brackets
219\& (...) Groups subexpressions for capturing to $1, $2...
220\& (?:...) Groups subexpressions without capturing (cluster)
221\& | Matches either the subexpression preceding or following it
222\& \e1, \e2 ... The text from the Nth group
223.Ve
224.Sh "\s-1ESCAPE\s0 \s-1SEQUENCES\s0"
225.IX Subsection "ESCAPE SEQUENCES"
226These work as in normal strings.
227.PP
228.Vb 11
229\& \ea Alarm (beep)
230\& \ee Escape
231\& \ef Formfeed
232\& \en Newline
233\& \er Carriage return
234\& \et Tab
235\& \e037 Any octal ASCII value
236\& \ex7f Any hexadecimal ASCII value
237\& \ex{263a} A wide hexadecimal value
238\& \ecx Control-x
239\& \eN{name} A named character
240.Ve
241.PP
242.Vb 6
243\& \el Lowercase next character
244\& \eu Titlecase next character
245\& \eL Lowercase until \eE
246\& \eU Uppercase until \eE
247\& \eQ Disable pattern metacharacters until \eE
248\& \eE End case modification
249.Ve
250.PP
251For Titlecase, see \*(L"Titlecase\*(R".
252.PP
253This one works differently from normal strings:
254.PP
255.Vb 1
256\& \eb An assertion, not backspace, except in a character class
257.Ve
258.Sh "\s-1CHARACTER\s0 \s-1CLASSES\s0"
259.IX Subsection "CHARACTER CLASSES"
260.Vb 4
261\& [amy] Match 'a', 'm' or 'y'
262\& [f-j] Dash specifies "range"
263\& [f-j-] Dash escaped or at start or end means 'dash'
264\& [^f-j] Caret indicates "match any character _except_ these"
265.Ve
266.PP
267The following sequences work within or without a character class.
268The first six are locale aware, all are Unicode aware. The default
269character class equivalent are given. See perllocale and
270perlunicode for details.
271.PP
272.Vb 6
273\& \ed A digit [0-9]
274\& \eD A nondigit [^0-9]
275\& \ew A word character [a-zA-Z0-9_]
276\& \eW A non-word character [^a-zA-Z0-9_]
277\& \es A whitespace character [ \et\en\er\ef]
278\& \eS A non-whitespace character [^ \et\en\er\ef]
279.Ve
280.PP
281.Vb 6
282\& \eC Match a byte (with Unicode, '.' matches a character)
283\& \epP Match P-named (Unicode) property
284\& \ep{...} Match Unicode property with long name
285\& \ePP Match non-P
286\& \eP{...} Match lack of Unicode property with long name
287\& \eX Match extended unicode sequence
288.Ve
289.PP
290\&\s-1POSIX\s0 character classes and their Unicode and Perl equivalents:
291.PP
292.Vb 15
293\& alnum IsAlnum Alphanumeric
294\& alpha IsAlpha Alphabetic
295\& ascii IsASCII Any ASCII char
296\& blank IsSpace [ \et] Horizontal whitespace (GNU extension)
297\& cntrl IsCntrl Control characters
298\& digit IsDigit \ed Digits
299\& graph IsGraph Alphanumeric and punctuation
300\& lower IsLower Lowercase chars (locale and Unicode aware)
301\& print IsPrint Alphanumeric, punct, and space
302\& punct IsPunct Punctuation
303\& space IsSpace [\es\eck] Whitespace
304\& IsSpacePerl \es Perl's whitespace definition
305\& upper IsUpper Uppercase chars (locale and Unicode aware)
306\& word IsWord \ew Alphanumeric plus _ (Perl extension)
307\& xdigit IsXDigit [0-9A-Fa-f] Hexadecimal digit
308.Ve
309.PP
310Within a character class:
311.PP
312.Vb 3
313\& POSIX traditional Unicode
314\& [:digit:] \ed \ep{IsDigit}
315\& [:^digit:] \eD \eP{IsDigit}
316.Ve
317.Sh "\s-1ANCHORS\s0"
318.IX Subsection "ANCHORS"
319All are zero-width assertions.
320.PP
321.Vb 8
322\& ^ Match string start (or line, if /m is used)
323\& $ Match string end (or line, if /m is used) or before newline
324\& \eb Match word boundary (between \ew and \eW)
325\& \eB Match except at word boundary (between \ew and \ew or \eW and \eW)
326\& \eA Match string start (regardless of /m)
327\& \eZ Match string end (before optional newline)
328\& \ez Match absolute string end
329\& \eG Match where previous m//g left off
330.Ve
331.Sh "\s-1QUANTIFIERS\s0"
332.IX Subsection "QUANTIFIERS"
333Quantifiers are greedy by default \*(-- match the \fBlongest\fR leftmost.
334.PP
335.Vb 8
336\& Maximal Minimal Allowed range
337\& ------- ------- -------------
338\& {n,m} {n,m}? Must occur at least n times but no more than m times
339\& {n,} {n,}? Must occur at least n times
340\& {n} {n}? Must occur exactly n times
341\& * *? 0 or more times (same as {0,})
342\& + +? 1 or more times (same as {1,})
343\& ? ?? 0 or 1 time (same as {0,1})
344.Ve
345.PP
346There is no quantifier {,n} \*(-- that gets understood as a literal string.
347.Sh "\s-1EXTENDED\s0 \s-1CONSTRUCTS\s0"
348.IX Subsection "EXTENDED CONSTRUCTS"
349.Vb 11
350\& (?#text) A comment
351\& (?imxs-imsx:...) Enable/disable option (as per m// modifiers)
352\& (?=...) Zero-width positive lookahead assertion
353\& (?!...) Zero-width negative lookahead assertion
354\& (?<=...) Zero-width positive lookbehind assertion
355\& (?<!...) Zero-width negative lookbehind assertion
356\& (?>...) Grab what we can, prohibit backtracking
357\& (?{ code }) Embedded code, return value becomes $^R
358\& (??{ code }) Dynamic regex, return value used as regex
359\& (?(cond)yes|no) cond being integer corresponding to capturing parens
360\& (?(cond)yes) or a lookaround/eval zero-width assertion
361.Ve
362.Sh "\s-1VARIABLES\s0"
363.IX Subsection "VARIABLES"
364.Vb 2
365\& $_ Default variable for operators to use
366\& $* Enable multiline matching (deprecated; not in 5.9.0 or later)
367.Ve
368.PP
369.Vb 3
370\& $& Entire matched string
371\& $` Everything prior to matched string
372\& $' Everything after to matched string
373.Ve
374.PP
375The use of those last three will slow down \fBall\fR regex use
376within your program. Consult perlvar for \f(CW@LAST_MATCH_START\fR
377to see equivalent expressions that won't cause slow down.
378See also Devel::SawAmpersand.
379.PP
380.Vb 6
381\& $1, $2 ... hold the Xth captured expr
382\& $+ Last parenthesized pattern match
383\& $^N Holds the most recently closed capture
384\& $^R Holds the result of the last (?{...}) expr
385\& @- Offsets of starts of groups. $-[0] holds start of whole match
386\& @+ Offsets of ends of groups. $+[0] holds end of whole match
387.Ve
388.PP
389Captured groups are numbered according to their \fIopening\fR paren.
390.Sh "\s-1FUNCTIONS\s0"
391.IX Subsection "FUNCTIONS"
392.Vb 4
393\& lc Lowercase a string
394\& lcfirst Lowercase first char of a string
395\& uc Uppercase a string
396\& ucfirst Titlecase first char of a string
397.Ve
398.PP
399.Vb 4
400\& pos Return or set current match position
401\& quotemeta Quote metacharacters
402\& reset Reset ?pattern? status
403\& study Analyze string for optimizing matching
404.Ve
405.PP
406.Vb 1
407\& split Use regex to split a string into parts
408.Ve
409.PP
410The first four of these are like the escape sequences \f(CW\*(C`\eL\*(C'\fR, \f(CW\*(C`\el\*(C'\fR,
411\&\f(CW\*(C`\eU\*(C'\fR, and \f(CW\*(C`\eu\*(C'\fR. For Titlecase, see \*(L"Titlecase\*(R".
412.Sh "\s-1TERMINOLOGY\s0"
413.IX Subsection "TERMINOLOGY"
414\fITitlecase\fR
415.IX Subsection "Titlecase"
416.PP
417Unicode concept which most often is equal to uppercase, but for
418certain characters like the German \*(L"sharp s\*(R" there is a difference.
419.SH "AUTHOR"
420.IX Header "AUTHOR"
421Iain Truskett.
422.PP
423This document may be distributed under the same terms as Perl itself.
424.SH "SEE ALSO"
425.IX Header "SEE ALSO"
426.IP "\(bu" 4
427perlretut for a tutorial on regular expressions.
428.IP "\(bu" 4
429perlrequick for a rapid tutorial.
430.IP "\(bu" 4
431perlre for more details.
432.IP "\(bu" 4
433perlvar for details on the variables.
434.IP "\(bu" 4
435perlop for details on the operators.
436.IP "\(bu" 4
437perlfunc for details on the functions.
438.IP "\(bu" 4
439perlfaq6 for FAQs on regular expressions.
440.IP "\(bu" 4
441The re module to alter behaviour and aid
442debugging.
443.IP "\(bu" 4
444\&\*(L"Debugging regular expressions\*(R" in perldebug
445.IP "\(bu" 4
446perluniintro, perlunicode, charnames and locale
447for details on regexes and internationalisation.
448.IP "\(bu" 4
449\&\fIMastering Regular Expressions\fR by Jeffrey Friedl
450(\fIhttp://regex.info/\fR) for a thorough grounding and
451reference on the topic.
452.SH "THANKS"
453.IX Header "THANKS"
454David P.C. Wollmann,
455Richard Soderberg,
456Sean M. Burke,
457Tom Christiansen,
458Jim Cromie,
459and
460Jeffrey Goff
461for useful advice.