1Regexp::Common::balanceUds(e3r)Contributed Perl DocumentRaetgieoxnp::Common::balanced(3)
2
3
4

NAME

6       Regexp::Common::balanced -- provide regexes for strings with balanced
7       parenthesized delimiters or arbitrary delimiters.
8

SYNOPSIS

10           use Regexp::Common qw /balanced/;
11
12           while (<>) {
13               /$RE{balanced}{-parens=>'()'}/
14                                          and print q{balanced parentheses\n};
15           }
16

DESCRIPTION

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       Returns a pattern that matches a string that starts with the nominated
25       opening parenthesis or bracket, contains characters and properly nested
26       parenthesized subsequences, and ends in the matching parenthesis.
27
28       More than one type of parenthesis can be specified:
29
30               $RE{balanced}{-parens=>'(){}'}
31
32       in which case all specified parenthesis types must be correctly
33       balanced within the string.
34
35       Since version 2013030901, $1 will always be set (to the entire matched
36       substring), regardless whether "{-keep}" is used or not.
37
38   "$RE{balanced}{-begin => "begin"}{-end => "end"}"
39       Returns a pattern that matches a string that is properly balanced using
40       the begin and end strings as start and end delimiters.  Multiple sets
41       of begin and end strings can be given by separating them by "|"s (which
42       can be escaped with a backslash).
43
44           qr/$RE{balanced}{-begin => "do|if|case"}{-end => "done|fi|esac"}/
45
46       will match properly balanced strings that either start with do and end
47       with done, start with if and end with fi, or start with case and end
48       with esac.
49
50       If -end contains less cases than -begin, the last case of -end is
51       repeated. If it contains more cases than -begin, the extra cases are
52       ignored. If either of -begin or -end isn't given, or is empty, -begin
53       => '(' and -end => ')' are assumed.
54
55       Since version 2013030901, $1 will always be set (to the entire matched
56       substring), regardless whether "{-keep}" is used or not.
57
58   Note
59       Since version 2013030901 the pattern will make of the recursive
60       construct "(?-1)", instead of using the problematic "(??{ })"
61       construct.  This fixes an problem that was introduced in the 5.17
62       development track.
63

SEE ALSO

65       Regexp::Common for a general description of how to use this interface.
66

AUTHOR

68       Damian Conway (damian@conway.org)
69

MAINTENANCE

71       This package is maintained by Abigail (regexp-common@abigail.be).
72

BUGS AND IRRITATIONS

74       Bound to be plenty.
75
76       For a start, there are many common regexes missing.  Send them in to
77       regexp-common@abigail.be.
78
80       This software is Copyright (c) 2001 - 2017, Damian Conway and Abigail.
81
82       This module is free software, and maybe used under any of the following
83       licenses:
84
85        1) The Perl Artistic License.     See the file COPYRIGHT.AL.
86        2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
87        3) The BSD License.               See the file COPYRIGHT.BSD.
88        4) The MIT License.               See the file COPYRIGHT.MIT.
89
90
91
92perl v5.38.0                      2023-07-21       Regexp::Common::balanced(3)
Impressum