Is there a perl function to convert a string to a regex string?

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi

I have a string like http://www.google.com/news that I want to convert to something like:

"(^|\.)google\.com\/news"

Is there a perl function that does this for me? If not can anyone suggest some code? as using ~m is very hard to do, as it 'cleans' the input string after the first pass, meaning I can't do everything I want to.

Thanks
 
Ah In the end I gave up looking and wrote this:

Code:
        $var=~s/\/|\./\\$&/g;
        $var=~s/http:\\\/\\\/|www\\\.|\\\/\*//g;
        push @singleRow, $regexPrefix.$var.$regexSuffix;

Anyone know of a more efficient way?

Thanks
 
Last edited:
Back
Top Bottom