in reply to Re: avoiding a particular character or set of characters
in thread avoiding a particular character or set of characters

cant i have a solution like
$str ="check this out";
if this sentence has out do not replace it
if($str =~ s#check this [^out]#check this one#){ }
is there some way to achieve this
one more thing i am not traversing line by line.
the whole java file i am taking as a single line
using undef $/;

Replies are listed 'Best First'.
Re^3: avoiding a particular character or set of characters
by prasadbabu (Prior) on Mar 27, 2006 at 15:31 UTC

    Hi neeha, you cannot use character class here, rather you have to use negative look head.

    change

    if($str =~ s#check this [^out]#check this one#){ }

    into

    $str ="$str ="check this out check this here";"; $str =~ s#check this ((?!out).)+#check this one#gs; print $str;

    Prasad

Re^3: avoiding a particular character or set of characters
by neeha (Novice) on Mar 27, 2006 at 15:27 UTC
    my problem is
    /** * public void method1(); * is deprecated */ public void method1();
    in this case my code replaces to
    /** * replaced code */ public void method1();
    It dont want to replace anything in the comments
    and my code reads the entire java file as a single line.