in reply to Re: Regex problem
in thread Regex problem

FunkyMonk:

I think you meant:

my $value = 'sample1\\*sample2\\*sample3\\*sample4\\*sample5'; print $value,"\n"; $value =~ s#\\\*#STAR#g; print $value,"\n";

as the \ is a special character and needs to be quoted in strings and regexes. The * is special in the regex and also needs quoting.

...roboticus

UPDATE: ikegami just pointed out to me that I am a doofus incorrect, as demonstrated:

my $value = 'sample1\\*sample2\\*sample3\\*sample4\\*sample5'; my $value2 = 'sample1\*sample2\*sample3\*sample4\*sample5'; if ($value eq $value2) { print "I am a studly programmer\n"; } else { print "I am a doofus\n"; }

Replies are listed 'Best First'.
Re^3: Regex problem
by ikegami (Patriarch) on Aug 03, 2007 at 00:14 UTC

    In single-quoted literals, escaping \ is optional if it's not followed by \ or the string delimiter.

    $x = 'a\b'; print("$x\n"); $x = 'a\\b'; print("$x\n");
    a\b a\b