$rhs .= "hello"; $i = "\n"; if ($i =~ m/[ -~]/) { $rhs .= $i; } else { $rhs .= "."; } $rhs .= "world"; print("$rhs\n"); # Prints: hello.world
You regexp reads as "contains a valid char". Maybe you need one of the following (equivalent to each other) regexps.
$i !~ m/[^ -~]/ # Doesn't contain invalid chars
$i =~ m/^[ -~]*\z/ # Only contains valid chars
In reply to Re: regex incorrectly matching newline
by ikegami
in thread regex incorrectly matching newline
by bfdi533
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |