Skip to content

Instantly share code, notes, and snippets.

@ahogen
Last active August 16, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahogen/90baa39a74271e0bb2ceccb065863e41 to your computer and use it in GitHub Desktop.
Save ahogen/90baa39a74271e0bb2ceccb065863e41 to your computer and use it in GitHub Desktop.
(0x\w{1,2})\s+0x(\w{1,2})\s+0x(\w{1,2})\s+0x(\w{1,2})

This regex will capture groups of 4 byte strings. It assumes the following:

  • All byte strings have a "0x" prefix
  • All byte strings are only seperated by white space
  • There are always two hex-digits in each byte string. Meaning a zero should always look like "0x00" and not "0x0".

Notice how each byte is in a capture group. This means you can concatenate the 4 capture groups, resulting in a 32-bit hex string.

Example:

0x01 0x7d 0x3d 0x00 
0xff 0xff 0xff 0xff 
0xfe 0xbe 0x7d 0x00 
0xff 0xff 0xff 0xff 
0xf9 0x1b 0x4c 0x00

In the Atom text editor, you can access capture groups with a dollar sign and the capture group number (see Atom issue #351). Put the regex statement above into the "Find" box, and the statement below into the "Replace" box.

$1$2$3$4, 

Now, clicking "Replace All" in Atom, should result in the following output:

0x017d3d00, 
0xffffffff, 
0xfebe7d00, 
0xffffffff, 
0xf91b4c00,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment