DB<49> sub english_num { my ($pre,$num) = @_; my $eng = join "-", ma +p {(qw/zero one two three four five six seven \ eight nine/)[$_] } split //,$num; return "$pre \\$eng"} DB<50> $txt =" some text No. 345 other text No. 123 end text" DB<51> $txt =~ s/(No.) (\d{3})/english_num($1,$2)/ge DB<52> say $txt some text No. \three-four-five other text No. \one-two-three end text
In case you are sure that it's always exactly 3 digits, you can also use a hardwired regex, with a lookup array
s/(No.) (\d)(\d)(\d)/$1 \\$nums[$2]-$nums[$3]-$nums[$4]/g
DB<94> $_ =" some text No. 345 other text No. 123 end text" DB<95> p some text No. 345 other text No. 123 end text DB<96> s/(No.) (\d)(\d)(\d)/$1 \\$nums[$2]-$nums[$3]-$nums[$4]/g DB<97> p some text No. \three-four-five other text No. \one-two-three end text
after reading the OP again, please provide an SSCCE clarifying input and expected output.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: multiple-pass search?
by LanX
in thread multiple-pass search?
by propellerhat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |