in reply to Detecting numbers continued
You give no example of a failing $text string in your most recent post nor in the previous ones (Pull 3-digit and 4-digit numbers from string, Recognizing numbers and creating links and Matching text in a string), but the advice offered is the same: do a single substitution. File s_4_digits_1.pl:
Output:use warnings; use strict; my $text = qq{foo 1234 \n 1234 bar \n1234\n 1 22 333 55555 666666}; print qq{[[$text]] \n}; my $digits_4 = qr{ \b \d{4} \b }xms; $text =~ s{ ($digits_4) } {<a href="script.pl?do=view&unit=$1"><b>$1</b></a>}xmsg; print qq{[[$text]] \n};
c:\@Work\Perl\monks\htmanning>perl s_4_digits_1.pl [[foo 1234 1234 bar 1234 1 22 333 55555 666666]] [[foo <a href="script.pl?do=view&unit=1234"><b>1234</b></a> <a href="script.pl?do=view&unit=1234"><b>1234</b></a> bar <a href="script.pl?do=view&unit=1234"><b>1234</b></a> 1 22 333 55555 666666]]
Give a man a fish: <%-(-(-(-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Detecting numbers continued
by htmanning (Friar) on Apr 24, 2015 at 01:38 UTC | |
by aaron_baugher (Curate) on Apr 24, 2015 at 02:33 UTC | |
by AnomalousMonk (Archbishop) on Apr 24, 2015 at 03:32 UTC |