in reply to Re: Regex question
in thread Regex question
G'day Bill,
I'd say you're on the right track creating a regex for $number and building up a more complex regex from there. Unfortunately, you're matching some things that you shouldn't.
$ perl -E ' say "$_: ", /1?\d{1,4}/ ? "Y" : "N" for qw{240 2 3600 1 10000 0 0000 19999 999999999}; ' 240: Y 2: Y 3600: Y 1: Y 10000: Y 0: Y 0000: Y 19999: Y 999999999: Y
I'd aim for a more stringent regex for $number.
$ perl -E ' say "$_: ", /(?<![0-9])(?:10000|[1-9][0-9]{0,3})(?![0-9])/ ? "Y" : + "N" for qw{240 2 3600 1 10000 0 0000 19999 999999999}; ' 240: Y 2: Y 3600: Y 1: Y 10000: Y 0: N 0000: N 19999: N 999999999: N
The OP is somewhat unclear in that it shows an example with spaces then says spaces are removed. Stuff is also removed, whatever that refers to. There's not much we can do about that beyond requesting clarification.
I'd also add ^ and $ (or equivalent) assertions to the final regex.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex question
by Marshall (Canon) on Sep 17, 2023 at 13:19 UTC |