in reply to pattern match

You have mentioned that you want to match only complex.12 and not complex.120, so you can try this.

You have not clearly mentioned that whether the number of digits vary, so you can try this

undef $/;

$file2 = <FILE>;
if ($file2 =~ /complex\.\d{2}/) { $pre = $` $line = ($pre =~ s/\n/\n/g); print "$line"; }

Prasad

Replies are listed 'Best First'.
Re^2: pattern match
by davido (Cardinal) on Oct 26, 2004 at 15:37 UTC

    Your regexp would match both "complex.12" and "complex.120", because though it is only looking for "complex." followed by two digits, it doesn't exclude anything that exceeds the minimum criteria.

    Perhaps you meant to say:

    m/^complex\.\d{2}$/

    ...or...

    m/\bcomplex\.\d{2}(?!\d)/

    The first example requires that the string contain nothing at all besides "complex.nn" (where nn is two digits). The second example allows the string to contain additional stuff, but requires that the "complex.nn" tag be clearly bounded by a word boundry on the left, and a digit-boundry on the right.


    Dave

      ok thanks for your advice.

      "Every time we make mistake there is a lesson to learn." i have read this qoute somewhere. (which i follow)

      --Prasad