develooper Front page | perl.beginners | Postings from May 2008

Re: howto simplfy this regex if ($string =~/^$match | $match | $match$/g){

Thread Previous | Thread Next
From:
Gunnar Hjalmarsson
Date:
May 3, 2008 22:45
Subject:
Re: howto simplfy this regex if ($string =~/^$match | $match | $match$/g){
itshardtogetone@hotmail.com wrote:
> How do I simplify the regex below so that it matches only the number 
> 1, henceforth it should return false if I match $string with $match.
> 
> use strict;
> use warnings;
> 
> my $string = "10 11 12 13 40";
> my $match = 1;
> 
> if ($string =~/^$match | $match | $match$/g){

Do you possibly mean something like:

     my $match = qr(\b1\b);
     if ( $string =~ /$match/ ) {

which would be true for the string

     my $string = "10 11 1 13 40";

but not for your original string.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About