Replace variable chain of text then adding pattern before and after
-
Hello. I’m trying to make a simple renaming mod on zomboid, but I need to edit around 600 text entries and my peanut brain can’t wrap around the functions. Basically, I need to extract the entries marked from this text:
together with the brackets and other signs at the end and paste them in the marked spaces from the following:
while keeping the prefix and suffixes. Does anyone know what’s the quickest approach for this? I have around 600 entries to edit and copy pasting them would take me way too much time.What I thought was somehow delete everything else that doesn’t comes after "item " with some kind of function, making a list of only the item ID’s then adding “TweakItem(“Tsarcraft.” as some prefix and “”,“DisplayCategory”,“MediaCas”);” as suffix with a line break, but I have no idea how to do that.
Thanks in advance.
-
@VenomNihil said in Replace variable chain of text then adding pattern before and after:
What I thought was somehow delete everything else that doesn’t comes after "item " with some kind of function, making a list of only the item ID’s then adding “TweakItem(“Tsarcraft.” as some prefix and “”,“DisplayCategory”,“MediaCas”);” as suffix with a line break, but I have no idea how to do that.
As a suggestion you could do it in 3 steps (much as you thought it might happen):
- Bookmark lines with
item
starting in the leftmost column (assuming that’s where it is) by using “Mark” function, typing^item
and ticking “bookmark line” and setting the search mode to “regular expression”. Click on Mark All. - Every line which starts with
item
will have a blue sphere marking it. Right click on this area of the margin and select “remove unmarked lines”. - Hopefully the lines left contain the text you want to alter. So next you use the Replace function and type:
Find What:(?-s)^item (.+)
Replace With:TweakItem\(“Tsarcraft.${1}”,“DisplayCategory”,“MediaCas”\);
Before you click on Replace All confirm that the double quotes you supplied (and which I’ve inserted here) are correct. Typing these into posts without code around them is problematic as the posting engine loves to alter the quote characters. Again this is a regular expression so set the search mode accordingly. Note that I preceded the(
and)
charcters with a\
which signifies they are to be that character not interpreted as a meta-character.
Now as you have not supplied actual text as examples (only images) we don’t have anything to copy and test with. If you find this isn’t working you need to read the pinned post at the start of the Help Wanted section (Please Read This Before Posting) and follow those instructions.
Terry
- Bookmark lines with
-
I don’t like the idea of “destroying” data in a solution. For novice users, this could lead to accidents like needing the original file and accidentally saving it after a data removal operation that harvests a subset of the data. Sure, there’s Undo, but…
So I’d maybe do this (similar to Terry’s but a bit different):
- Using “Mark” function, typing
(?-s)^item .+
and setting the search mode to Regular expression. Click on Mark All. Note that the desired text is red-marked. Click on Copy Marked Text. - Create a new N++ tab and do a Ctrl+v paste there.
- Continue on as Terry said in his step 3.
- Using “Mark” function, typing
-
@Alan-Kilborn said in Replace variable chain of text then adding pattern before and after:
I don’t like the idea of “destroying” data in a solution.
Normally I’d agree however he did specifically state about somehow deleting the other lines. So I followed that idea.
Terry
-
Damn it’s been 5 days already? I completely forgot to reply
@Terry-R @Alan-Kilborn thanks a lot! It really helped, only the ^ doesn’t work with the spacing but I supposed is because I posted a screenshot. But just using " item " instead does the job. -
@VenomNihil said in Replace variable chain of text then adding pattern before and after:
the ^ doesn’t work with the spacing but I supposed is because I posted a screenshot. But just using " item " instead does the job.
Yes, it is tough to work from a screenshot; that’s why we have suggestions to not post them for this type of problem, or to post both a screenshot and the literal text. Apparently we failed to noticed this part of your original posting: