regex - How to remove a special character in a single word/variable -


my $var= "file/"; $var=~ /\w/; print "$var"; 

the expected outcome file doest work.

you using wrong operator. match operator (m/.../ or, using it, /.../) matching text. tells if string matches regex. not change string @ all.

what want substitution operator (s/.../.../). replaces matching text new. in case, want replace matching string empty string.

my $var= "file/"; $var =~ s/\w//; # // empty replacement string print "$var"; 

but that's still not correct \w matches word character (alphanumerics , underscore). need \w, matches non-word character.

my $var= "file/"; $var =~ s/\w//; # // empty replacement string print "$var"; 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -