Help with regexmatch

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Help with regexmatch

11 Apr 2023, 03:01

Could anyone please tell me the regexmatch to remove part of the filename of a series of files. It should remove everything from the first "_" to the second "_" found, both "_" included. Thank you very much.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with regexmatch

11 Apr 2023, 03:05

Code: Select all

#Requires AutoHotkey v1.1.36.02
MsgBox % RegExReplace("aaaaa_bbbb_CCCC", "_[^_]+_") ; aaaaaCCCC
-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Re: Help with regexmatch

11 Apr 2023, 04:09

Thank you, but in this case also other "_" after that are also removed:

Code: Select all

MsgBox % RegExReplace("aaaaa_bbbb_CCCC_dddd_eeee.mp4", "_[^_]+_")
result: aaaaCCCCeeee.mp4
expected: aaaaCCCC_dddd_eeee.mp4
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with regexmatch

11 Apr 2023, 04:14

Code: Select all

MsgBox % RegExReplace("aaaaa_bbbb_CCCC_dddd_eeee.mp4", "_[^_]+_", , , 1) ; aaaaaCCCC_dddd_eeee.mp4
-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Re: Help with regexmatch

11 Apr 2023, 04:21

Thank you very much. It works great.

Finally (and sorry to bother you again), how would it be to have this transformation?

aaaaa_bbbb_CCCC_dddd_eeee.mp4 --> aaaaa_CCCC_dddd_eeee.mp4
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with regexmatch

11 Apr 2023, 04:35

Code: Select all

MsgBox % RegExReplace("aaaaa_bbbb_CCCC_dddd_eeee.mp4", "_[^_]+(?=_)", , , 1) ; aaaaa_CCCC_dddd_eeee.mp4
-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Re: Help with regexmatch

11 Apr 2023, 04:46

Thank you so much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 85 guests