Replace only the first \n

General questions about using WildEdit

Moderators: AmigoJack, helios, bbadmin, Bob Hansen, MudGuard

Post Reply
ahouglum
Posts: 2
Joined: Thu Jun 18, 2009 5:19 pm

Replace only the first \n

Post 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. :?:
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post 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....
Hope this was helpful.............good luck,
Bob
ahouglum
Posts: 2
Joined: Thu Jun 18, 2009 5:19 pm

didn't work

Post by ahouglum »

No, it replaced every thing with ~XXX~
ben_josephs
Posts: 2456
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
Post Reply