diff options
| author | Teddy Wing | 2022-05-25 02:22:51 +0200 |
|---|---|---|
| committer | Teddy Wing | 2022-05-25 02:23:44 +0200 |
| commit | 48fefa2bee2e67743f8056dea93eed2ccf28653a (patch) | |
| tree | d5c611a5d604d9559fb211ef383387ca5fc89f27 | |
| parent | b42dc03982cd87ed10dbbc6d339004805fc39fd7 (diff) | |
| download | readline-incdec-48fefa2bee2e67743f8056dea93eed2ccf28653a.tar.bz2 | |
incdec.pm: Extract number matching regex to a variable
So it can be re-used in both the find and the replace steps without
being duplicated now that it's become more complicated.
| -rw-r--r-- | incdec.pm | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -27,10 +27,12 @@ sub incdec { $point_position ||= 0; $is_backward ||= 0; + my $number_regex = '-?([1-9]\d*|0\D|0$)'; + my $start_position = 0; my $previous_match_start = 0; my $i = 0; - while ($line =~ /(-?([1-9]\d*|0\D|0$))/g) { + while ($line =~ /($number_regex)/g) { if ($is_backward) { # Set start position to the current match start. This gives us the # correct start position when incrementing the last number in a @@ -64,7 +66,7 @@ sub incdec { } pos($line) = $start_position; - $line =~ s/\G(-?([1-9]\d*|0\D|0$))/$1 + $increment_by/e; + $line =~ s/\G($number_regex)/$1 + $increment_by/e; return ($line, $start_position); } |
