in reply to regex incorrectly matching newline
$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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex incorrectly matching newline
by bfdi533 (Friar) on Jun 23, 2006 at 18:46 UTC | |
by ikegami (Patriarch) on Jun 23, 2006 at 19:21 UTC |