in reply to Replacing 3 and 4 digit numbers.

I think the advice of others about using an (X|HT)ML parser to avoid certain "URLs" (whatever that means in your particular circumstances) is wisely given and well taken. However, if you can clearly define a "URL" in the context of your data (and that's a big if!), here's a neat approach that will work. (This needs Perl version 5.10+ regex extensions.) (Untested)

my $digits_3_4 = qr{ \b \d{3,4} \b }xms; my $url = qr{ <a> ... </a> }xms; $text =~ s{ $url (*SKIP) (*FAIL) | ($digits_3_4) } {<a href="resident-info.pl?do_what=view&unit=$1"><b>$1</b></ +a>}xmsg;
Please see Special Backtracking Control Verbs for  (*SKIP) (*FAIL) in perlre.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Replacing 3 and 4 digit numbers.
by Discipulus (Canon) on Apr 08, 2016 at 08:02 UTC
    $text =~ s{ $url (*SKIP) (*FAIL) | ($digits_3_4) }
    wow! perlre is defintively an unxplored (by me) continent! thanks AnomalousMonk

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      :D "old style" that is backwards compatible

      s{ (...) | (...) | ... }{ RepReplace($1,$2,$3); }ge; sub RepReplace { my( $link, $dig3, $num4 ) = @_; if( defined $link ){ return $link; ### change nothing } ...
Re^2: Replacing 3 and 4 digit numbers.
by afoken (Chancellor) on Apr 08, 2016 at 16:29 UTC
    Please see Special Backtracking Control Verbs for (*SKIP) (*FAIL) in perlre.

    Hey! You fooled me into thinking that you want htmanning to RTFM.

    Discipulus++'s answer was a real insight. I had never expected that readable words are part of perl's RE syntax. I've looked into my local perl, and lo and behold, it's supported even here, in 5.18.1 (but still marked experimental).

    The only thing that I don't like is that perlre does not state since which version this feature is supported.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      ... since which version this feature is supported.

      Special Backtracking Control Verbs first appeared in Perl 5.10.


      Give a man a fish:  <%-{-{-{-<

Re^2: Replacing 3 and 4 digit numbers.
by htmanning (Friar) on Apr 10, 2016 at 09:31 UTC
    Thanks so much for the replies. This works, but I have a different issue now. I need to ignore years. How can I set some parameters to ignore, 2014, 2015, 2016, 2017, etc.?

      What is the context in which these digit groups appear? With what other four-digit groups that you want to process might they be confused? Can you give some brief example input and desired output? What code have you written so far? What is the "this" that works?


      Give a man a fish:  <%-{-{-{-<

        This is a log for a building of apartments. Each apartment/unit number is a 3 or 4 digits. When a log entry is entered, I use the code to link the 3 or 4 digit number to an informational page about the apt. that is generated by resident-info.pl. It works wee, except sometimes people update the log and enter a date in the log itself. When that happens the year is then tagged as a unit number when it shouldn't be. Also, there have been times when someone has included HTML tags in the log entry, and perhaps a URL that includes a number that is not a unit number. The code above then isolates part of that HTML and tries to place a new URL with bold tags around the number in the manually entered HTML. That screws things up. I hope that's clear.