Re: Perl treats period as space in string
by choroba (Cardinal) on Jul 20, 2021 at 20:48 UTC
|
use feature qw{ fc };
my $phrase = fc 'club.market';
if (-1 != index fc $string, $phrase) { ...
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Perl treats period as space in string
by tybalt89 (Monsignor) on Jul 20, 2021 at 20:14 UTC
|
if ($string =~ m/\Q$phrase\E/i){
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
if ($string =~ /^\Q$phrase\E\z/i)
or
use feature qw( fc );
if (fc($string) eq fc($phrase))
The second is probably faster.
Seeking work! You can reach me at ikegami@adaelis.com
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Perl treats period as space in string
by GrandFather (Saint) on Jul 20, 2021 at 20:59 UTC
|
The '.' is matching any non-newline character which is what it does in a regular expression when it hasn't been quoted. See Perl regular expression metacharacters.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] [Watch: Dir/Any] |
Re: Perl treats period as space in string
by AnomalousMonk (Archbishop) on Jul 21, 2021 at 00:57 UTC
|
| [reply] [Watch: Dir/Any] [d/l] |
|
Today I noticed grex ...
grex is a library as well as a command-line utility that is meant to simplify the often complicated and tedious task of creating regular expressions. It does so by automatically generating a single regular expression from user-provided test cases ...
This project has started as a Rust port of the JavaScript tool regexgen written by Devon Govett ...
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: Perl treats period as space in string
by perlfan (Vicar) on Jul 20, 2021 at 22:07 UTC
|
It's confusing to define the regexp in a variable, then place it there between the /../; The reason is that in the assignment it's very much just a string. When you place it in the regexp context, it suddenly means something different (i.e., the "dot"). So don't do that unless it's very cleary you're dynamically defining your regular expression, otherwise you're just making it more confusing for you and anyone else who may be looking at this even in the very near future. | [reply] [Watch: Dir/Any] [d/l] |
|
use strict;
use warnings;
use Test::More tests => 2;
my $phrase = qr/club\.market/;
unlike( 'club market', $phrase, 'not match space' );
like( 'club.market', $phrase, 'match period' );
RESULT,
1..2
ok 1 - not match space
ok 2 - match period
| [reply] [Watch: Dir/Any] [d/l] [select] |