add a space between bytes except for the last byte

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

add a space between bytes except for the last byte

Postby mingwu » Thu Oct 09, 2008 12:46 am

Test data:

80040400062CECCCFF00000001D73B00

Desired result:

80 04 04 00 06 2C EC CC FF 00 00 00 01 D7 3B 00

Note that there should not be a space at the end of the line.

The following simple tactics does not make me happy:

Find What: (\w{2})
Replace With: $1
(Note that there is a space after $1).

So the real challenge is: how do you implement the logic "the byte beofre new lines".

Thanks for your help in advance.

Ming Wu
mingwu
Newbie
 
Posts: 3
Joined: Fri Aug 22, 2008 6:39 am

Re: add a space between bytes except for the last byte

Postby pietzcker » Thu Oct 09, 2008 1:38 am

(\w{2})(?![\r\n])

matches two characters unless they are followed by a newline character.
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: add a space between bytes except for the last byte

Postby jorrasdk » Thu Oct 09, 2008 1:51 am

Just add a positive lookahead to your regexp:

(\w{2})(?=\w)

ie. only match the two next word characters if succeeded by a word character

replace \1<blank>

re-edit: Oops. Simultaneous posting. But mine will also work if the last line in the file is not followed by a single newline ;-)
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: add a space between bytes except for the last byte

Postby pietzcker » Thu Oct 09, 2008 2:25 am

Unless mingwu is using an older UE version (pre-14, I think) which still has the positive lookahead bug :)
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: add a space between bytes except for the last byte

Postby mingwu » Sun Oct 19, 2008 5:26 am

Thanks guys.

Both version worked perfectly.

There is no bug at all, since I do not need to add a blank for a byte which is immediately followed by a newline.
mingwu
Newbie
 
Posts: 3
Joined: Fri Aug 22, 2008 6:39 am


Return to Find/Replace/Regular Expressions