in reply to regex question Underscores, lines and paratheses.
I want to a regex which is able to match a-zA-Z0-9_- and parantheses.
use strict; use warnings; use Test::More; my @good = ( 'a', '321', '(321)', 'a(321-)_HGF' ); my @bad = ( '"@$', '~', '[{' ); my $re = qr/^[a-zA-Z0-9_()-]+$/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }
See also How to ask better questions using Test::More and sample data
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex question Underscores, lines and parentheses.
by Aldebaran (Curate) on May 07, 2019 at 17:10 UTC |