in reply to Re: puzzled by pages
in thread puzzled by pages

product1name is always the same, I want to allow for 84 different prefixes to be checked they are always at least 3 characters the product1name is the end of the url I am checking, I need this to switch to a personalized login message depending on which url for the site visitors land on.

Replies are listed 'Best First'.
Re^3: puzzled by pages
by kyle (Abbot) on Jun 10, 2008 at 19:54 UTC

    Perhaps this pattern is what you need.

    $server_name =~ m{ \A # start of string .{1,3} # 1-3 characters \. # a literal period product1help\.com # literal 'product1help.com' }xms;

    If you want to know what the prefix matched actually was, use this:

    $server_name =~ m{ \A # start of string ( # start capture 1 .{1,3} # 1-3 characters ) # end capture 1 \. # a literal period product1help\.com # literal 'product1help.com' }xms; my $prefix = $1;
      I don't understand why this is not working, if my url is sef.mlxhelp.com it fails, if its www.mlxhelp.com it works.. what gives can anyone clarify why this fails? why does it even look at the prefix part?
      sub transform { if (!$Session->{'isAuthenticated'}) { if ($Request->ServerVariables("SERVER_NAME")->item()=~/(\mlxhelp +*)\.com/) { $Response->write("this is what I got $1"); $trns=$Server->MapPath("Transforms/pLogin.xsl"); return $trns; } if ($Request->ServerVariables("SERVER_NAME")->item()=~/(\tem +pohelp*)\.com/) { $Response->write("this is what I got $1"); $trns=$Server->MapPath("Transforms/tpLogin.xsl"); return $trns; } }

        In a regular expression, "\t" is a tab character, and I'm not sure what "\m" is, if anything.

        use Test::More 'tests' => 2; ok( 'sef.mlxhelp.com' =~ /(\.mlxhelp)\.com/, q{'sef.mlxhelp.com' matches} ); ok( 'www.mlxhelp.com' =~ /(\.mlxhelp)\.com/, q{'www.mlxhelp.com' matches} );

        Note that these will always put ".mlxhelp" in $1 when they match because the capturing parentheses are around that literal string.