in reply to REGEX Help

In the first case it is probably sufficient to ensure that the preceeding character was a digit and that the following character is a non-word character so s/(?<=\d)mp\b//g should do that one.

In the second case it is actually even simpler, no zero width look back assertion required: s/\s+\d+x Zoom//g.

Update: fixed broken regex. Was s/(><=\d)mp\b//g


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: REGEX Help
by Anonymous Monk on Jun 24, 2006 at 08:29 UTC
    Thanks a lot.
    The second problem got resolved but the first issue still
    persists. What could be missing in this solution


    $original_text="Olympus xModel 3.1mp"; $original_text=~ s/(><=\d)mp\b//g; print "\n$original_text";
    Regards Habib

      The absence of a stupid typo! Sorry, the regex should have been $original_text=~ s/(?<=\d)mp\b//g;.

      By the way I strongly recommend that you add use strict; use warnings; to any script you write. You then need to declare variables using my, but many problems get found before they bite hard.

      You should also browse the following documentation, probably in the order given: perlretut, perlre and perlreref.


      DWIM is Perl's answer to Gödel

      Hi, Your regex $original_text=~ s/(><=\d)mp\b//g; is not complete. You do have have a replacement string. Try this instead. $original_text=~ s/(.+)mp/$1/g;

      Sriram