in reply to Re: brackets help
in thread brackets help
Presuming any non-word character should be replaced with an underscore:
my $s = 'Hello ( World ).'; $s =~ s/\W+/_/g; # Replace all sequences of [^a-zA-Z0-9_] with _ $s =~ s/_$//; # Remove trailing _ if present
Note that if you wanted to replace strings containing multiple sequential _, you'd have to change \W to the appropriate character class.
|
|---|