Need help replacing a pattern of characters

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 540
Joined: 22 Oct 2015, 17:56

Need help replacing a pattern of characters

20 Dec 2020, 20:23

I have a CSV with character sets that I need to replace.

These characters are link the following:

amaxb7568bj
amaxj74tyl9
amaxk74r98z
amaxy74jzs8
amaxs74fjt5
amaxp74cd6t
amax4744bnr
amaxk74fygz
amaxv747crm
amaxu747vd2
amaxj749hjy
amaxg74brvl
amaxf74bglr
amaxx77l8ls

So... they start with 'amax' and then are followed by 7 more characters.
This will always be the same pattern.

I want to delete all occurrences of these words (leave all other text as is).

I'd like to do 2 ways.

1. Open the file in a text editor and replace all occurrences with nothing, i.e. delete.
and
2. Open a CSV read in and replace all and output the text in the CSV and save the same file.

Not sure where to start. Assuming I need regex? I never got to grip with regex in AHK. It seems to be a little different than elsewhere in other languages (or am I wrong in saying that?)

Looking for help starting off.
Assuming I cant use a simple string replace.

Thanks.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Need help replacing a pattern of characters

20 Dec 2020, 20:31

Code: Select all

str =
(
not,amaxb7568bj,this
not,amaxb756,this
notamaxj74tyl9this
notamaxj74tyl9thisorthatortheother
notamaxj74tyl9thisorthatortheother,done
)
Clipboard =
Clipboard := RegExReplace(str, "amax[^,\n]{7,}")
ClipWait, 2
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
MsgBox, 64, Results, %Clipboard%
omar
Posts: 540
Joined: 22 Oct 2015, 17:56

Re: Need help replacing a pattern of characters

20 Dec 2020, 21:12

Very nice 🙂
Could you explain the code for me?

"amax[^,\n]{7,}"

What are the ^ , \n characters?
What does the {,7} do? I'm guessing it says amax + 7 characters?

ALSO:

MsgBox, 48, Error, An error occurred while waiting for the clipboard.

MsgBox, 64, Results, %Clipboard%

What does the 48 and 64 do?

Thanks.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Need help replacing a pattern of characters

20 Dec 2020, 21:17

:arrow: MsgBox, See "Group #2: Icon"

:arrow: RegEx

Brackets define a class of characters. ^ in a class means "Not". \n means line feed. {7,} means "at least 7 times".
omar
Posts: 540
Joined: 22 Oct 2015, 17:56

Re: Need help replacing a pattern of characters

20 Dec 2020, 21:20

Thanks
I'll read up more from your links and will try the code 👍🏼

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 383 guests