1Regexp::Common::balanceUds(e3r)Contributed Perl DocumentRaetgieoxnp::Common::balanced(3)
2
3
4
6 Regexp::Common::balanced -- provide regexes for strings with balanced
7 parenthesized delimiters or arbitrary delimiters.
8
10 use Regexp::Common qw /balanced/;
11
12 while (<>) {
13 /$RE{balanced}{-parens=>'()'}/
14 and print q{balanced parentheses\n};
15 }
16
18 Please consult the manual of Regexp::Common for a general description
19 of the works of this interface.
20
21 Do not use this module directly, but load it via Regexp::Common.
22
23 $RE{balanced}{-parens}
24
25 Returns a pattern that matches a string that starts with the nominated
26 opening parenthesis or bracket, contains characters and properly nested
27 parenthesized subsequences, and ends in the matching parenthesis.
28
29 More than one type of parenthesis can be specified:
30
31 $RE{balanced}{-parens=>'(){}'}
32
33 in which case all specified parenthesis types must be correctly bal‐
34 anced within the string.
35
36 If we are using C{-keep} (See Regexp::Common):
37
38 $1 captures the entire expression
39
40 $RE{balanced}{-begin => "begin"}{-end => "end"}
41
42 Returns a pattern that matches a string that is properly balanced using
43 the begin and end strings as start and end delimiters. Multiple sets
44 of begin and end strings can be given by separating them by "⎪"s (which
45 can be escaped with a backslash).
46
47 qr/$RE{balanced}{-begin => "do⎪if⎪case"}{-end => "done⎪fi⎪esac"}/
48
49 will match properly balanced strings that either start with do and end
50 with done, start with if and end with fi, or start with case and end
51 with esac.
52
53 If -end contains less cases than -begin, the last case of -end is
54 repeated. If it contains more cases than -begin, the extra cases are
55 ignored. If either of -begin or -end isn't given, or is empty, -begin
56 => '(' and -end => ')' are assumed.
57
58 If we are using C{-keep} (See Regexp::Common):
59
60 $1 captures the entire expression
61
63 $Log: balanced.pm,v $
64 Revision 2.101 2003/02/01 22:55:31 abigail
65 Changed Copyright years
66
67 Revision 2.100 2003/01/21 23:19:40 abigail
68 The whole world understands RCS/CVS version numbers, that 1.9 is an
69 older version than 1.10. Except CPAN. Curse the idiot(s) who think
70 that version numbers are floats (in which universe do floats have
71 more than one decimal dot?).
72 Everything is bumped to version 2.100 because CPAN couldn't deal
73 with the fact one file had version 1.10.
74
75 Revision 1.6 2002/08/20 15:20:48 abigail
76 Documented -begin and -end
77
78 Revision 1.5 2002/08/08 23:57:33 abigail
79 Added HISTORY section.
80
81 Revision 1.4 2002/08/08 23:53:54 abigail
82 Reworked and extended $RE{balanced}. It now takes multiple arbitrary
83 length delimiters. -parens is just a short-cut for some of the common,
84 simpler cases.
85
86 Revision 1.3 2002/08/05 12:16:58 abigail
87 Fixed 'Regex::' and 'Rexexp::' typos to 'Regexp::'
88 (Found my Mike Castle).
89
90 Revision 1.2 2002/07/25 22:37:44 abigail
91 Added 'use strict'.
92 Added 'no_defaults' to 'use Regexp::Common' to prevent loaded of all
93 defaults.
94
95 Revision 1.1 2002/07/25 22:14:44 abigail
96 Factored out from Regexp::Common.
97
99 Regexp::Common for a general description of how to use this interface.
100
102 Damian Conway (damian@conway.org)
103
105 This package is maintained by Abigail (regexp-common@abigail.nl).
106
108 Bound to be plenty.
109
110 For a start, there are many common regexes missing. Send them in to
111 regexp-common@abigail.nl.
112
114 Copyright (c) 2001 - 2003, Damian Conway. All Rights Reserved.
115 This module is free software. It may be used, redistributed
116 and/or modified under the terms of the Perl Artistic License
117 (see http://www.perl.com/perl/misc/Artistic.html)
118
119
120
121perl v5.8.8 2003-03-23 Regexp::Common::balanced(3)