in reply to Re^7: Regex help \b & \Q
in thread Regex help \b & \Q
# I've changed all x-es to spaces (for comparison). for my $line ('1234', ' 1234', '1234 ', ' 1234 ', '12345', ' 12345 ',, ' 123456 '){ print map { sprintf "%10s: $_\n", "'$line'" } join ' ', map { $line =~ qr/$_/x ? 'OK' : 'NO' } '(?<! \d) \d{4} (?! \d)', '(?<! \D) \d{4} (?! \D)', '\b \d{4} \b ', '\B \d{4} \B ', } __END__ '1234': OK OK OK NO ' 1234': OK NO OK NO '1234 ': OK NO OK NO ' 1234 ': OK NO OK NO '12345': NO OK NO NO ' 12345 ': NO NO NO NO ' 123456 ': NO OK NO OK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Regex help \b & \Q
by AnomalousMonk (Archbishop) on Apr 15, 2016 at 12:20 UTC |