extracting something from text using regex

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ik4u
Posts: 80
Joined: 05 Jun 2020, 13:52
Contact:

extracting something from text using regex

24 Jul 2021, 12:29

Clipboard has a page of text and numbers and special characters. however somewhere in text exist, any integer, 0-99(space)dollars
example;
88 dollars
5 dollars
0 dollars
30 dollars
I need help to Regex code tso that Clipboard = "the number before dollars"
from above examples
Clipboard = 88
Clipboard = 5
Clipboard = 0
Clipboard = 30
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: extracting something from text using regex

24 Jul 2021, 13:41

Code: Select all

Clipboard := ""
Clipboard := "88 dollars"
ClipWait, 1

MsgBox,, before, % Clipboard

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", match)
MsgBox,, after,  % Clipboard := match
ik4u
Posts: 80
Joined: 05 Jun 2020, 13:52
Contact:

Re: extracting something from text using regex

24 Jul 2021, 14:22

Xtra wrote:
24 Jul 2021, 13:41

Code: Select all

Clipboard := ""
Clipboard := "88 dollars"
ClipWait, 1

MsgBox,, before, % Clipboard

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", match)
MsgBox,, after,  % Clipboard := match
your code failed to give me the result im looking for, perhaps I didnt explain correctly.
I will try once more

Clipboard = ; entire page of text, numbers & special characters approximately 1500 characters.
Somewhere in the text appears a single or 2 digit (0-99) followed by (space) and the word dollars.
i want a regex code, to remove all except for the integer thats before dollars so
x = clipboard
msgbox, %x% must diplay thsi 1or 2 digit number
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: extracting something from text using regex

24 Jul 2021, 15:50

You only need this part. (everything above these lines was just to show as an example)

Code: Select all

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", match)
MsgBox,, after,  % Clipboard := match
Copy your text to the clipboard and then run the code.
ik4u
Posts: 80
Joined: 05 Jun 2020, 13:52
Contact:

Re: extracting something from text using regex

27 Jul 2021, 11:17

Xtra wrote:
24 Jul 2021, 15:50
You only need this part. (everything above these lines was just to show as an example)

Code: Select all

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", match)
MsgBox,, after,  % Clipboard := match
[Mod edit: quote tags fixed.]

dear friend how can include above regex code in my script without message box so that
x = match
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: extracting something from text using regex

27 Jul 2021, 11:49

Code: Select all

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", match)
x := match
or

Code: Select all

RegExMatch(Clipboard, "\d{1,2}(?= dollars)", x)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Nerafius and 103 guests