vkp has asked for the wisdom of the Perl Monks concerning the following question:
hi there, i need to replace some string in a line. The string could be (for example) nf=6 or nfabc = 7 or nf = {(3)*(3)} or nfabc = {(1)*(1)}. I am using following
$_=~/ +nf.*? *\=? *\d+/for nf =4 or nfabc=4. and second is
$_=~/ +nf.*? *\= *.*?\}/for nf or nfabc ={} like stuff. The second is working fine. But the first is also targeting the {} stuff and it is taking pattern like nf={4} g=4 matched, and returning $& as nf={4} g=4. I know it is because of \d+ in last. But i want to make first line only to match nf=4 or nfabc=4. Not to {} stuff, because it means different for me. Please modify first code line so that i can get correct match. thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: need help to replace string in a line
by moritz (Cardinal) on Nov 24, 2012 at 16:22 UTC |