Regexreplace space and other caracters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pilu
Posts: 84
Joined: 22 Jun 2018, 01:13

Regexreplace space and other caracters

26 Nov 2020, 05:56

Hi all,

Can somebody help me, how can i set the regexreplace that it let only the numbers and letters?

Code: Select all

RegExReplace (Clipboard, "[^0-9]+", " ")
thanks
mcl
Posts: 357
Joined: 04 May 2018, 16:35

Re: Regexreplace space and other caracters

26 Nov 2020, 06:12

Do not put space between command and parenthesis.
Use empty string if you want to remove characters completely and not replace them with space.

Code: Select all

Clipboard := RegExReplace(Clipboard, "[^0-9A-Za-z]", "")
github://oGDIp - GDI+ wrapper for AHK v1.1
sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Regexreplace space and other caracters

26 Nov 2020, 07:27

Hi:
Same approach as @mcl 's, but shorter

Code: Select all

Clipboard := RegExReplace(Clipboard, "\W", "")
teadrinker
Posts: 4364
Joined: 29 Mar 2015, 09:41
Contact:

Re: Regexreplace space and other caracters

26 Nov 2020, 07:58

sofista wrote: Same approach as @mcl 's
No, look:

Code: Select all

str = abc___###123
MsgBox, % RegExReplace(str, "[^0-9A-Za-z]", "")
MsgBox, % RegExReplace(str, "\W", "")
This one is shorter:

Code: Select all

str = abc___###123
MsgBox, % RegExReplace(str, "i)[^\da-z]")
sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Regexreplace space and other caracters  Topic is solved

26 Nov 2020, 08:08

teadrinker wrote:
26 Nov 2020, 07:58
sofista wrote: Same approach as @mcl 's
No, look:

Code: Select all

str = abc___###123
MsgBox, % RegExReplace(str, "[^0-9A-Za-z]", "")
MsgBox, % RegExReplace(str, "\W", "")
This one is shorter:

Code: Select all

str = abc___###123
MsgBox, % RegExReplace(str, "i)[^\da-z]")
Good point :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, arrondark, MerlinSilk, slowwd and 105 guests