Insert CR/LF after N words ?!??

Find, replace, find in files, replace in files, regular expressions

Insert CR/LF after N words ?!??

Postby pgmende » Mon Aug 21, 2006 8:37 am

Hello!

I need to insert a CR/LF after every two words.

So I tried this with the search/replace function, but it doesn't work.

Searching for ^(*^) ^(*^) finds two words, but I can't replace the second space with a "^p".

For example:
Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism.

should become:
Welcome to
the IDM
Forum. This
forum is
meant as
a user-to-user
support mechanism.


Can anyone help me?

Regards from Germany!
User avatar
pgmende
Newbie
 
Posts: 1
Joined: Sun Aug 20, 2006 11:00 pm

Re: Insert CR/LF after N words ?!??

Postby Mofi » Mon Aug 21, 2006 10:35 am

Well, you searched for

0 or more occurrences of any character,
followed by a single space,
followed by 0 or more occurrences of any character.

Because after the second * no character is following, the second * means always 0 characters.

I suggest following UltraEdit style regex:

Find: ^([~ ^t^p]+^)[ ^t]+^([~ ^t^p]+^)[ ^t]++
Replace: ^1 ^2^p

[~ ^t^p]+ = a string with at least 1 character which can have all characters except a space, a tab or a CRLF.

Or without the tab if your file does not contain tabs:

Find: ^([~ ^p]+^) +^([~ ^p]+^) ++
Replace: ^1 ^2^p
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Find/Replace/Regular Expressions