in reply to multiple-pass search?
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Lingua::EN::Numbers qw{ num2en }; my $text = 'abc No. 347 xyz'; $text =~ s/No\. \K(\d+)/join "", "\\", map num2en($_), split m{}, $1/g +e; print $text; # abc No. \threefourseven xyz
I used /e which evaluates the replacement part as code. The regex matches "No. " followed by a number, but replaces just the number due to \K. It splits the number into digits, replaces each with the word (via num2en) and joins them together with a \ at the beginning.
|
|---|