From ea3260541f81be7b288c20da920084271625b1a3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 18 Aug 2021 01:17:58 +0200 Subject: Test regex replacement starting from a given position Set `pos()` to enable us to increment a number in the middle of a string. --- pos.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 pos.pl diff --git a/pos.pl b/pos.pl new file mode 100644 index 0000000..f9c365f --- /dev/null +++ b/pos.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl -w + +use strict; + +my $test = 'test 12 0 45'; + +$test =~ /(\d+)/g; +pos($test) = 7; +$test =~ s/\G([^\d]*)(\d+)/$1 . ($2 + 1)/e; + +print "$test\n"; -- cgit v1.2.3