[help] search and replace with searched + more
-
Hello! I need some help with replacing.
I got a file cointaining some lines with values, like:AI_LEVEL=90
…some other text
AI_LEVEL=100
…some other text
AI_LEVEL=94
and so onI would like each time i find the line “AI_LEVEL” despite of its value, i can add a new line containing “AI_AGGRESSION=1”, but keeping the AI_LEVEL value
Like this:AI_LEVEL=90
AI_AGGRESSION=1
…some other text
AI_LEVEL=100
AI_AGGRESSION=1
…some other text
AI_LEVEL=94
AI_AGGRESSION=1
and so onAny help on this please? Thanks a lot!!
-
@Alberto-Zanot said in [help] search and replace with searched + more:
Any help on this please? Thanks a lot!!
This can be achieved by using a regular epression (regex). If you aren’t sure on what these are there is a FAQ post called “Where to find REGular EXpressions (RegEx) documentation?”
So using the Replace function (set search mode to regular expression) we have:
Find What:(\x20*)(AI_LEVEL=\d+)(\R)
Replace With:${1}${2}${3}${1}AI_AGGRESSION=1${3}
You can hit either “Replace” for one change at a time, or “Replace All” which changes the entire tab’s contents.As you hadn’t enclosed your example in some code for displaying it’s possible you may have meant for some leading spaces to display. If so, they were removed by the formatting engine before the post showed. I’ve taken this into account and my regex will work if there are spaces as well as no spaces. The inserted line will be indented to the same amount.
You may want to insert this code into regex101.com and it will describe the function of each portion. From there you may want to start learning some regex yourself.
If you find that this does not solve the issue, then check what you posted. As I say, the posting engine can adjust some text. If this is the case, read the pinned post (Please Read This Before Posting) at the start of the Help Wanted section about how to post examples correctly.
Terry
-
@Terry-R
Worked perfectly! Thanks a lot!!!