1Regexp::Common::list(3)User Contributed Perl DocumentatioRnegexp::Common::list(3)
2
3
4
6 Regexp::Common::list -- provide regexes for lists
7
9 use Regexp::Common qw /list/;
10
11 while (<>) {
12 /$RE{list}{-pat => '\w+'}/ and print "List of words";
13 /$RE{list}{-pat => $RE{num}{real}}/ and print "List of numbers";
14 }
15
17 Please consult the manual of Regexp::Common for a general description
18 of the works of this interface.
19
20 Do not use this module directly, but load it via Regexp::Common.
21
22 $RE{list}{-pat}{-sep}{-lastsep}
23 Returns a pattern matching a list of (at least two) substrings.
24
25 If "-pat=P" is specified, it defines the pattern for each substring in
26 the list. By default, P is "qr/.*?\S/". In Regexp::Common 0.02 or
27 earlier, the default pattern was "qr/.*?/". But that will match a
28 single space, causing unintended parsing of "a, b, and c" as a list of
29 four elements instead of 3 (with "-word" being "(?:and)"). One
30 consequence is that a list of the form "a,,b" will no longer be parsed.
31 Use the pattern "qr /.*?/" to be able to parse this, but see the
32 previous remark.
33
34 If "-sep=P" is specified, it defines the pattern P to be used as a
35 separator between each pair of substrings in the list, except the final
36 two. By default P is "qr/\s*,\s*/".
37
38 If "-lastsep=P" is specified, it defines the pattern P to be used as a
39 separator between the final two substrings in the list. By default P
40 is the same as the pattern specified by the "-sep" flag.
41
42 For example:
43
44 $RE{list}{-pat=>'\w+'} # match a list of word chars
45 $RE{list}{-pat=>$RE{num}{real}} # match a list of numbers
46 $RE{list}{-sep=>"\t"} # match a tab-separated list
47 $RE{list}{-lastsep=>',\s+and\s+'} # match a proper English list
48
49 Under "-keep":
50
51 $1 captures the entire list
52
53 $2 captures the last separator
54
55 $RE{list}{conj}{-word=PATTERN}
56 An alias for $RE{list}{-lastsep=>'\s*,?\s*PATTERN\s*'}
57
58 If "-word" is not specified, the default pattern is "qr/and|or/".
59
60 For example:
61
62 $RE{list}{conj}{-word=>'et'} # match Jean, Paul, et Satre
63 $RE{list}{conj}{-word=>'oder'} # match Bonn, Koln oder Hamburg
64
65 $RE{list}{and}
66 An alias for $RE{list}{conj}{-word=>'and'}
67
68 $RE{list}{or}
69 An alias for $RE{list}{conj}{-word=>'or'}
70
72 Regexp::Common for a general description of how to use this interface.
73
75 Damian Conway (damian@conway.org)
76
78 This package is maintained by Abigail (regexp-common@abigail.be).
79
81 Bound to be plenty.
82
83 For a start, there are many common regexes missing. Send them in to
84 regexp-common@abigail.be.
85
87 This software is Copyright (c) 2001 - 2017, Damian Conway and Abigail.
88
89 This module is free software, and maybe used under any of the following
90 licenses:
91
92 1) The Perl Artistic License. See the file COPYRIGHT.AL.
93 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
94 3) The BSD License. See the file COPYRIGHT.BSD.
95 4) The MIT License. See the file COPYRIGHT.MIT.
96
97
98
99perl v5.34.0 2021-07-22 Regexp::Common::list(3)