david
david

Reputation: 4278

add a space/split up pairs of characters

How do you add a space/split up between each pair of characters.

eg 0x5C8934A3   -->  0x 5C 89 34 A3

I could use a macro but it just took to long to manualy set it up because the size of the strings.

what i know is how to find using. but i can not get the replace to work correctly Please show me how to preform this.

[0][x][0-9A-F]+    
match 
0x5C8934A3

Upvotes: 8

Views: 22067

Answers (3)

stema
stema

Reputation: 92976

Notepad++ has very limited regexes so you have to use something like this:

Search for

(..)

and replace with

\1 

(Note there is a space after the \1!)

(..) means find two characters and store them

\1 get the characters stored in the first capturing group

Precondition for this simple solution is that there are only such strings and nothing else. And it will then add an unneeded space after the word. If this is not not wanted you can remove it afterwards.

Upvotes: 31

Tim Pietzcker
Tim Pietzcker

Reputation: 336128

I don't have Notepad++ installed here, but on my editor you can search for \B(?=(?:[0-9A-F]{2})+\b) and replace all with a single space.

Explanation:

\B            # only match within words
(?=           # Assert that from the current position...
 (?:          # ...the following can be matched:
  [0-9A-F]{2} # a succession of two hexadecimal digits
 )+           # once or more,
 \b           # ending at a word boundary.
)             # End of lookahead

Upvotes: 2

alex
alex

Reputation: 490183

This regex will return groups of two non newline (\n) characters.

.{2}

If you want match \n too, use the character range [\s\S].

If you want to be explicit to match the hexadecimal pattern, you could use...

^(0x)([\da-z]{2})+

(be sure to use the i pattern modifier.)

You didn't specify your language, but you could then join the matches with a space character or do a replace with $0 (or whatever holds the entire match, such as $& in JavaScript).

Upvotes: 1

Related Questions