Graeme McLaren wrote:
Afternoon all, I'm trying to to a regular expression to search and
replace + with \+

I need to escape the + because it is getting used as an operator
instead of a literal string, this is what I have so far:

$terms[$i] =~ s/\+ /\ \\\+/g;

Basically the result of searching for c++ should return results
containing that string.

I'm not sure about what you really need. Please consider the following:

    $_ = 'the c++ programming language';
    print '$_ contains "c++"', "\n" if /\Qc++/;
    s/\+/\\+/g;
    print;

Outputs:
$_ contains "c++"
the c\+\+ programming language

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to