in reply to Re: Set the flag
in thread Set the flag

The above code is replacing every <p> with <con>.
I have to replace only in the first <p> and skip replacing of <con> for other <p> tag.
The replacement should work only for the first <p> tag in a file and I have to replace only in the last </p> and skip replacing of </con> for other </p> tag.
The replacement should work only for the last </p> tag in a file Please help me on this.

Replies are listed 'Best First'.
Re^3: Set the flag
by ikegami (Patriarch) on Nov 06, 2009 at 06:19 UTC

    The above code is replacing every <p> with <con>.

    No, just the first. You'd need to add /g to make it replace every instance.

    You said you needed to search the file. You aren't searching every line, right?