RegexMatch Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
zuzu_kuc
Posts: 35
Joined: 30 Mar 2016, 12:36

RegexMatch

09 Jan 2020, 05:09

Hi,
i cant figure out how to get multiple matchs.
in my clipboard is:

101221 tady muze byt taky
29,90 tady taky nejaky text
39,90/ 25%
104036
199,- 99,90 trochu pismenek
74

and i want to get just bold numbers, it can be 5-8 digits. Somethimes is just one in clipboard, somethimes i have 10x this numbers.

i have tried this:

Code: Select all

clipboard := RegExReplace(clipboard,"(\r|\n)", " ") ; to remove lines - maybe useful?
clipboard := RegExReplace(Clipboard,"(\d{5,8})\s", "$1", pocetART) ; how many times is my needle in clipboard - maybe for loop?
clipboard := RegExReplace(Clipboard,"(\d{5,8})", "$1") ; but this give me nothing :/
i have also tried this:

Code: Select all

RegExMatch(clipboard,"s)(\d{5,8})", art) ; without success :/
my goal is get numbes
as new line or not for example: 104036 101221 15547 556878 ....

Thank you for your advice.
User avatar
TLM
Posts: 1589
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: RegexMatch  Topic is solved

09 Jan 2020, 05:52

this loop will parse a string and append each match to list:

Code: Select all

while ( Pos:=RegExMatch(clipboard,"\d{5,8}", digits, !Pos?(1,list:=""):StrLen(digits)+Pos) )
	list .= digits " "

clipboard := RTrim(list)

msgbox % clipboard
zuzu_kuc
Posts: 35
Joined: 30 Mar 2016, 12:36

Re: RegexMatch

09 Jan 2020, 06:04

it works perfectly! Thanks
Can you please explane little bit part of code, i have no idea what happend after var digits :) And i rly want to know :)
while ( Pos:=RegExMatch(clipboard,"\d{5,8}", digits, !Pos?(1,list:=""):StrLen(digits)+Pos) )
User avatar
TLM
Posts: 1589
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: RegexMatch

09 Jan 2020, 06:42

It's a ternary condition for:
If Position equals 0 or nothing !Pos, then the Starting Position is the beginning of the string or 1 (1, also empty list variable ,list:="")
else the next Starting Position begins at the string length of the match StrLen(digits), plus the Position of the match in the string +Pos

It's basically a short cut for this:

Code: Select all

pos 	:= 1 	; begin at 1
list 	:= "" 	; clear list

while ( pos := RegExMatch( clipboard,"s)\d{5,8}", digits, pos ) )
{
	list 	.= digits " "
	pos 	+= StrLen( digits )
}

clipboard := RTrim( list )

msgbox % clipboard
Also if pos isn't assigned a number at the start,
the While loop immediately resolves and won't start parsing the string.
zuzu_kuc
Posts: 35
Joined: 30 Mar 2016, 12:36

Re: RegexMatch

09 Jan 2020, 07:18

Thank you very MUCH!
teadrinker
Posts: 2052
Joined: 29 Mar 2015, 09:41
Contact:

Re: RegexMatch

09 Jan 2020, 09:51

A short way:

Code: Select all

str =
(
101221 tady muze byt taky
29,90 tady taky nejaky text
39,90/ 25`%
104036
199,- 99,90 trochu pismenek
74
)
MsgBox, % Trim( RegExReplace(str, "s).*?(\d{5,8})|.*", "$1 ") )

Return to “Ask For Help”

Who is online

Users browsing this forum: AmDeG 11, Bing [Bot], Chunjee, Kellyzkorner_NJ, mad3d, Netocon, twstech and 68 guests