#Mostly Clueless Please Help With Regex/Find/Replace in Notepad++

46 messages · Page 1 of 1 (latest)

golden nymph
#

So I wasnt sure what tag applies to this and will just put Windows sorry.

In short I use notepad++ to mess around moding game files. Iv just recently learned a LITTLE about Regex, 'regular expressions' and the ToolBucket Multiline Find and Replace Plugin.
Id like to be able to search for two or more separate criteria at once I know this can be done with ( )? and another ( )?, however I do not understand how to properly replace the first group with ONLY 'x' and the second group with ONLY 'y' and NOT have both groups get replaced with 'x'&'y'.

Reminder I have basically no clue about coding.

Ill give an example via text and in my images:
Testing and learning file

Stuff
Thingo1
thingy2
#END
So how would I search for 'Thingo1' to replace it with 'Random1' at the same time searching for 'thingy2' and replacing it with 'random2' without having 'Thingo1' be replaced with both 'Random1random2'?

I know I could just search 1 at a time however Im almost certain this should be possible and would speed up my process.

median haven
#

Regex only finds matches, it doesn't have any kind of logic built into it to be able to say "if X do Y, if A do B." So what you want to do isn't actually possible.

golden nymph
#

😦 really?

#

oh

#

but what about the \1\2 type stuff?

#

I thought the solution had something to do with those \ thingies

median haven
#

That's for inserting groups from the match into the replacement.

golden nymph
#

isnt that what I want?

median haven
#

There's no if this then that logic to it

golden nymph
#

I dont know how to use \

#

oh 😦 so I cant have \1 only replace the first group and \2 only replace the second group? D:

median haven
#

Nah, (hello)(world) \1 would be "hello" and \2 would be "world", there's no way to say "\1 is hello insert foo"

golden nymph
#

Depression 😦

#

what to do then? just Find things 1 at a time if I only want 'x' replaced with 'y' I cant do multiple searches and replaces at the same time with notepad++ uh

#

I was beginning to get so happy with my knowledge slowly coming along, beginning to think anything was possible felt godly then this brick wall

median haven
#

Ok, well you might be able to do that in a round about way.

(thing1)?(.*?)(thing2)?

And then you could do replacement1 \2 replacement2. Essentially you match what's between the words you're looking for and re-insert that between what you want the words replaced with.

#

You'd actually probably need to get rid of the first and last ? just because otherwise it will likely not work at all since stuff is ambiguous.

golden nymph
#

^ Im getting baby headed reading and trying to understand this 😦

#

is why Iv gone so long in my 23 years without learning 2 code makes me really aware of my idiocy

median haven
#

Regex is an entirely different beast.

golden nymph
#

let me try and replicate what youve outlined in NP++ step by step

median haven
#

It's very terse and hard to grok what it's doing

golden nymph
#

to confirm if Im warm or cold

#

so heres my demo file right

#

and I want to replace 'Thingo1' with 'Replacement1' and 'thingy2' with 'replacement2'

median haven
#

It'll only work if you want to replace them together.

golden nymph
#

so Id bring up the multiline find/replace

median haven
#

So every time there's a Thingo1 followed by a Thingo2

golden nymph
#

oh

#

well Im gonna try what you put above in the find

median haven
#

You can't change the replace field based on what you matched, you can only insert matches into it

golden nymph
#

ohhhhhhhhhhhhhhhh

#

so like let me rephrase to confirm I get it

#

so like Find can take many different orders and Replace can ONLY give 1 universalized result that will be the same exact result for each order?

#

if so thats a BUMMER

median haven
#

Yeah.

#

Pretty much.

golden nymph
#

okay well in any case I thank you very much oh wise one for saving me much frustration figuring out things are impossible on my own is 1000x the grief

#

❤️

median haven
#

👍 Sorry I couldn't give you better news haha

#

If you wanted to do stuff like that you could write a simple program using something like Python or JavaScript

golden nymph
#

Iv been informed of such 'simplicity' and ease of use do it your self program tool production things before and that is a bit more than Id like to chew at present

median haven
#

Understandable

golden nymph
#

when I feel ready, humble and able Ill come back here to you gang for helpers