Help with RegExReplace Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bad husband
Posts: 54
Joined: 21 Oct 2017, 13:38

Help with RegExReplace

18 Nov 2022, 22:40

hi, need help in removing two words in a sentence

string := 223344-OPERATIONS 21X700 (Line A)

need to remove OPERATIONS and (Line A)

final result should be 223344- 21X700

The sentence will always start with 6 digits and have a hyphen, but the word OPERATIONS could be short form OPER and the word in the brackets could also be short as well - (LNA) or (LA).

So maybe a rule to remove the word after the hyphen and then the end of the sentence with the brackets?

thanks for reading and helping
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Help with RegExReplace

19 Nov 2022, 00:06

Code: Select all

string := "223344-OPERATIONS 21X700 (Line A)"
MsgBox % RegExReplace(string , "^\d{6}-\K\w+|\([^()]*?\)$")
User avatar
Datapoint
Posts: 303
Joined: 18 Mar 2018, 17:06

Re: Help with RegExReplace  Topic is solved

19 Nov 2022, 00:11

Bad husband wrote:
18 Nov 2022, 22:40
final result should be 223344- 21X700

The sentence will always start with 6 digits and have a hyphen, but the word OPERATIONS could be short form OPER and the word in the brackets could also be short as well - (LNA) or (LA).

So maybe a rule to remove the word after the hyphen and then the end of the sentence with the brackets?
This should basically do what you are describing. Start with six digits, ignore the next word, then get a space and anything up to the (, then ignore the rest of the line.

Code: Select all

MsgBox % RegExReplace("223344-OPERATIONS 21X700 (Line A)", "^(\d{6}-)\w+(\s.+)\(.+", "$1$2")
https://regex101.com/r/6Rp7gB/1
Bad husband
Posts: 54
Joined: 21 Oct 2017, 13:38

Re: Help with RegExReplace

19 Nov 2022, 12:56

both work for my needs

Thanks for your help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], chubbychub, Chunjee and 73 guests