Page 1 of 1

Replace only the first \n

Posted: Thu Jun 18, 2009 5:21 pm
by ahouglum
I have a bunch of text files and I want to only replace the first instance of the \n with something else.

But, no matter what I do it replaces every \n!

Help. :?:

Posted: Thu Jun 18, 2009 10:18 pm
by Bob Hansen
Can't test on Wild Edit now, but does this work?

Find: ^(.*[^\n])\n(.*)
Replace with: \1~XXX~\2

Would replace the first "\n" with "~XXX~"

I know this DOES NOT work in TextPad, because it cannot scan multiple lines, but perhaps WildEdit can handle it....

didn't work

Posted: Thu Jun 18, 2009 10:47 pm
by ahouglum
No, it replaced every thing with ~XXX~

Posted: Fri Jun 19, 2009 9:24 am
by ben_josephs
\A should match the beginning of the file, but it doesn't seem to work: it matches the beginning of every line.

If your files aren't too big, you might try
Find what: ^([^\r\n]*)\r?\n(.*)
Replace with: $1 something else $2

[X] Regular expression
[X] Replacement format

Options
[ ] '.' does not match a newline character [i.e., not selected]
But this might be rather slow, as the regex matches and captures the whole file.