in reply to Regular Expression Problem

Your code looks correct, although as the other reply suggests if you wish to have an ampersand displayed in a browser you should probably use the '&' entity.

Have you verified that your form input contains what you think it does? For example no trailing whitespace, etc?

Steve
---
steve.org.uk

Replies are listed 'Best First'.
Re: Re: Regular Expression Problem
by Anonymous Monk on Mar 29, 2004 at 14:42 UTC
    The problem isn't where I want to print the "&" or not but where the string matchs. See the ex;
    If you do this:
    my $test = "A C Test"; if($test=~s/\bA C Test\b/A&C Test/){print "<b>$test</b>";}

    It will work. But if the value is coming from something like this:
    my $test_name = $in{'test_name'};
    It will nor work.
    That's my problem! Tks...

      This is why I said "Have you verified that your text contains what you think it does?".

      Print it out and see!

      In the code you give above, for example, you're testing against $test - but getting the input into $test_name - which isn't being used!

      Steve
      ---
      steve.org.uk
        I think that problem starts even before.
        I have a link like:
        <a href=\"applic.pl?trans=edit&action=edit&name=$name>
        The value from the header isn't parsing the "&".
      Have you tried using chomp to remove any trailing newlines? e.g. my $string = chomp($myinput);
        I got the solution for this problem
        I encoded the "&" on the url like "%26".
        After I coded this to do the translation
        if($name=~/(.*)&(.*?)/) { $name=~s/(.*)&(.*?)/$1%26$2/; print $name; } else { print $name; }

        Thank you for all your help!
        I think that problem starts even before.
        I have a link like:
        <a href=\"applic.pl?trans=edit&action=edit&name=$name>
        The value from the header isn't parsing the "&".