I'd like to clarify: You want to replace all space characters except for newline with underscore. You want to replace ( or ) with underscore. And you want to replace newline with space (0x20). Is that correct?
$str =~ s/[\h()]/_/g; $str =~ s/\n/ /g;
One issue you are probably having right now is that \s includes \n, so your newlines are being transliterated to _ (underscore) before the second substitution operator is invoked. By the time you call the second one, there are no more newlines to transliterate. The \h metacharacter class includes horizontal whitespace, but not vertical (ie, not \n). \h is mentioned in perluniprops.
Another problem is that \s on the righthand side of a s/// operator is just a plain old string with an escaped s. The \ gets dropped by the "quote-like-operator" interpolation, so even if \n had matched, it would have left you with s instead of space.
Dave
In reply to Re: Reg exp questions
by davido
in thread Reg exp questions
by carolw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |