Kajal_T Kajal_T - 1 year ago 90
Perl Question

Perl: Quantifier follows nothing in regex

I have written this line to replace

with space. But it returns error stating quantifier follows nothing in regex.

$element= ~ s/+/ /g;
$element= ~ s/=/ /g;

Is this correct? How do I combine both conditions in one?

Answer Source

+ has a special meaning in regexes: it's a quantifier meaning "1 or more". To use + literally, backslash it.

$element =~ s/\+/ /g;

But, if you want to replace both + and =, you can add them to a character class, where + loses its special meaning:

$element =~ s/[+=]/ /g;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download