aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm8
1 files changed, 5 insertions, 3 deletions
diff --git a/incdec.pm b/incdec.pm
index a979cf7..6e1d83f 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Teddy Wing
+# Copyright (c) 2021–2022 Teddy Wing
#
# This file is part of Incdec.
#
@@ -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 =~ /(-?\d+)/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(-?\d+)/$1 + $increment_by/e;
+ $line =~ s/\G($number_regex)/$1 + $increment_by/e;
return ($line, $start_position);
}