how to replace A or B or C by "1" ?

Get help with using AutoHotkey and its commands and hotkeys
partof
Posts: 15
Joined: 16 Jan 2016, 08:38

how to replace A or B or C by "1" ?

17 Jul 2017, 02:42

I kow how te replace a single instance:

Code: [Select all] [Download] GeSHi © Codebox Plus

Unwrapped := RegExReplace(Unwrapped, "\bA\b" , "1")


But how can I replace several instance in one?

(\b is to match the whole word)


(I did not find the answer here https://autohotkey.com/docs/commands/StringReplace.htm )
User avatar
Exaskryz
Posts: 2013
Joined: 17 Oct 2015, 20:28

Re: how to replace A or B or C by "1" ?

17 Jul 2017, 02:51

That code should replace several instances in one, because you omitted the Limit parameter in RegExReplace. (That is different from StringReplace.)

Even if you used StringReplace, so long as you omit the limit parameter in the function, it will replace all instances.

Edit, ooohh, you were looking to identify multiple possible needles in a single expression. My apologies, I misunderstood what you wanted. And that fault is on me because the code you provided should not support the hypothesis you were struggling with replacing multiple occurrences of the " A " instance.
Last edited by Exaskryz on 17 Jul 2017, 11:13, edited 1 time in total.
partof
Posts: 15
Joined: 16 Jan 2016, 08:38

Re: how to replace A or B or C by "1" ?

17 Jul 2017, 03:10

thank you for your reply but I don't understand it. Could you please give me an example of the syntax (replace A or B or C by "1")?
partof
Posts: 15
Joined: 16 Jan 2016, 08:38

Re: how to replace A or B or C by "1" ?

17 Jul 2017, 05:50

Thanks to Era_Scarecrow here is the answer:

Code: [Select all] [Download] GeSHi © Codebox Plus

Unwrapped:=RegExReplace(Unwrapped, "(A|B|C)", "1")


or to search/replace for the word only:

Code: [Select all] [Download] GeSHi © Codebox Plus

Unwrapped:=RegExReplace(Unwrapped, "(\bA\b|\bB\b|\bC\b)", "1")
User avatar
jeeswg
Posts: 1539
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to replace A or B or C by "1" ?

17 Jul 2017, 10:03

Here are some ideas:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Btw 'single instance' sounds like you want to replace an item the first time it occurs, and ignore the other occurrences. Perhaps saying something like you want to replace multiple needles v. a single a needle would make more sense.

Era_Scarecrow, good name, is that from a live chat forum? Cheers.

Return to “Ask For Help”

Who is online

Users browsing this forum: eekhelpspike, Yahoo [Bot] and 26 guests