in reply to Simple Regex drives me insane
This passes all both of your test cases:
use strict; use warnings; use Test::More tests => 4; my $re = qr/(?:#(\S+))?/; ok 'bli bla' =~ $re, 'No hash, matched'; is $1, undef, '$1 undef'; ok '#foo bli bla' =~ $re, 'With hash, matched'; is $1, 'foo', '$1 is foo';
See also How to ask better questions using Test::More and sample data.
🦛
|
|---|