0

i have hex code below. the regex find code can match the string, but replace code wont keep the original string. my question : how to fix replace code to keep original string. thx

hex txtfile:
5839343C12050D000020410A2B
B81E053E12050D0000A0410A2B
0AD7A33C12050D000020420A2B

replace txtfile :
5839343C
12050D000020410A2B
B81E053E
12050D0000A0410A2B
0AD7A33C
12050D000020420A2B

notepad++ regex code :
find--12050D0000.*04.0A2B\s
replace-- \n012050D0000.*04.*0A2B\n

1
  • You can't work with .* in the replacement, that will just literally mean a dot followed by an asterisk there. You need to use capture groups in your expression - (.*), and then use back references - $1, $2, etc. - in your replacement.
    – CBroe
    Commented Jul 5 at 12:25

2 Answers 2

1

You are using \s at the end of your pattern, but in your example data you match the 10A2B at the end of the example data. If there is no space or newline after it, then the last line will have no match.

In Notepad++ you could assert the end of the string with $

12050D0000.*04.*0A2B$

And replace with a newline followed by the match denoted as $0

\n$0

See a regex demo

enter image description here

0

To retain the input text use capture groups.

Use a find text of (12050D0000.*04.0A2B)\s and replace with \n\1\n. Ensure that "Regular expressions" is selected.

Note that this simple replacement can add unwanted blank lines if "Replace all" is pressed more than once. To avoid that I would suggest a more complex replacement:

Find (\w)(12050D0000.*04.0A2B)\s and replace with \1\n\2\n.

Not the answer you're looking for? Browse other questions tagged or ask your own question.