in reply to Re: Counting characters within regexp
in thread Counting characters within regexp

I used [\w|\.] to match either a an alphanumeric character or a real full stop - did I get that wrong?

The beginning of \w[\w|\.] is to allow for cases where an email address consists of the person's initial followed by a full stop followed by their surname - e.g. j.bloggs@...

EDIT - I guess I wanted (\w|\.) instead of [\w|\.]

Replies are listed 'Best First'.
Re^3: Counting characters within regexp
by hippo (Archbishop) on May 09, 2021 at 11:01 UTC

    Here is how to use a character class to achieve that.

    use strict; use warnings; use Test::More; my @good = ( 'a', '9', '_', ); my @bad = ( '-', '$', '?', ); my $re = qr/[\w.]/; plan tests => @good + @bad; like $_, $re, "match for '$_'" for @good; unlike $_, $re, "no match for '$_'" for @bad;

    🦛

Re^3: Counting characters within regexp
by LanX (Saint) on May 09, 2021 at 09:54 UTC