How do I replace strings of text while retaining numbers in middle of the line?
-
So, I am modding a game and have a .txt file in which I need to replace multiple, possibly hundreds of lines of this type :
owns = 116
to this
116 = { country_or_non_sovereign_subject_holds = ROOT }
The numbers after ‘owns =’ can be anything between 1-5000, so it can have 1 to 4 digits
What would be the easiest way to replace all of the lines in this file?
-
Hi @Juuso-Uu
A regular expression would be fine here. I assume the matching string is placed at the begining of a line. If this is not the case, please remove the
^
symbol from the Search expression.Search: ^owns = (\d{1,4}) Replace: $1 = { country_or_non_sovereign_subject_holds = ROOT }
Put the caret at the very beginning of the document, select just the
Regular Expression mode
and click onReplace All
.Take care and have fun!
-
Worked perfectly, thank you so much!!
-
Hello,
You can replace strings of text while retaining numbers in the middle of the line using RegEx.
Follow the steps:
Open your document in N++.
Go to the start of the document by clicking on ctrl+home.
Open The Replace Dialogue Box (ctrl+h).
Under search, mode Select regular expression.
write the following in the fields.
Find what: (?i)(?s)owns = (\d{1,4})
Replace with: $1 = { country_or_non_sovereign_subject_holds = ROOT }
Click on Replace All.Description:
(?s) enables dot matching newlines.
(?i) makes match case insensitive.
(owns) represents a literal string.
(\d) (digit) matches any single digit (same as [0-9] ).
{1,4} matches with a 1 to 4 digit number.
$1 refers to the first match (in this case $1 will refer to the number i.e. 116).