Reputation: 1
I have strings that look like this for example subnet 1 ims-0-x ip address
and I want to get rid of the -x
so it will be subnet 1 ims-0 ip address
I tried doing this regex replace
$string=~ s/\\-x//;
which is not working. I think my issue is that I am not escaping the dash properly. please help me fix that one line.
Upvotes: 0
Views: 121
Reputation: 1921
You are escaping a backslash and not the dash. With two backslashes (\\
), the first backslash escapes the second and it looks for a backslash in the string. It should be s/-x//
. You don't need to escape the -
.
use strict;
use warnings;
my $s = "subnet 1 ims-0-x ip address";
$s =~ s/-x//;
print "$s\n"
Upvotes: 1
Reputation: 526
I tried this and its working fine, /g is to replaceAll instances. The output is "subnet 1 ims-0 ip address"
$string = "vishwassubnet 1 ims-0-x ip address";
$string =~ s/-x//g;
print $string;
Upvotes: 0