1#!/usr/bin/perl 2# Copyright (C) 2015-2016 Sergey Poznyakoff <gray@gnu.org> 3# 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3, or (at your option) 7# any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17use strict; 18use warnings; 19 20use List::Regexp; 21use Getopt::Long qw(:config gnu_getopt no_ignore_case); 22use File::Basename; 23use Pod::Usage; 24use Pod::Man; 25 26use constant EX_OK => 0; 27use constant EX_USAGE => 1; 28 29my $progname = basename($0); 30my $progdescr = "creates a regexp matching all words in the command line"; 31my %opts = ( type => 'posix' ); 32 33GetOptions("h" => sub { 34 pod2usage(-message => "$progname: $progdescr", 35 -exitstatus => EX_OK); 36 }, 37 "help" => sub { 38 pod2usage(-exitstatus => EX_OK, -verbose => 2); 39 }, 40 "usage" => sub { 41 pod2usage(-exitstatus => EX_OK, -verbose => 0); 42 }, 43 "pcre" => sub { $opts{type} = $_[0] }, 44 "posix" => sub { $opts{type} = $_[0] }, 45 "emacs" => sub { $opts{type} = $_[0] }, 46 "exact" => sub { $opts{match} = $_[0] }, 47 "word" => sub { $opts{match} = $_[0] }, 48 "group" => \$opts{group}, 49 "debug" => \$opts{debug}) or exit(EX_USAGE); 50 51pod2usage(-exitstatus => EX_USAGE, -verbose => 0, -output => \*STDERR) 52 if $#ARGV == -1; 53 54print regexp_opt(\%opts, @ARGV); 55print "\n"; 56__END__ 57=head1 NAME 58 59regexp-opt - create a regexp matching all words in the command line 60 61=head1 SYNOPSIS 62 63B<regexp-opt> 64B<--debug> 65B<--emacs> 66B<--exact> 67B<--pcre> 68B<--posix> 69B<--word> 70I<STRING> [I<STRING>...] 71 72=head1 DESCRIPTION 73 74Creates a regular expression that will match any of the words listed in the 75command line. By default, POSIX extended regexp is created. 76 77=head1 OPTIONS 78 79=over 4 80 81=item B<--debug> 82 83Enable debugging output. 84 85=item B<--emacs> 86 87Create B<Emacs> regular expression. 88 89=item B<--exact> 90 91Create a regexp that will match only words appearing at a line alone. 92 93=item B<--pcre> 94 95Create Perl-compatible regular expression. 96 97=item B<--posix> 98 99Create POSIX extended regular expression (default). 100 101=item B<--word> 102 103Create regexp for matching whole words. 104 105=back 106 107=head1 AUTHOR 108 109Sergey Poznyakoff <gray@gnu.org> 110