Edited Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Edited

Post by fivefive » 24 May 2022, 09:34

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 24 May 2022, 09:38

Code: Select all

Str := "Adam bought an orange @ $1.50-2.00"
RegExMatch(Str, "(?<=@ \$)[0-9.]+", Price)
MsgBox, % Price

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 10:24

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 24 May 2022, 10:34

I think for your purpose, it would be better to check that it's a number:

Code: Select all

If Price is number
{
} Else

Note that I put the brace on the line below because you can't use it on the same line in this type of statement. The If Var is Type is a legacy type of statement that doesn't allow it.

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 10:44

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 24 May 2022, 10:48

No, because type checking is a legacy type of statement, it doesn't support expressions and can't be combined with other conditions. You can accomplish the same thing like this:

Code: Select all

If Price is number
	if (Price > 0.01)
	{
	} Else
You might need two else branches to handle all cases since the first could be true but not the other.

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 15:56

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 24 May 2022, 16:53

Code: Select all

Str := "A noisy and entertaining book cost $3, perfect for bedtime $9, and a chance to meet all the animals in the jungle. Told in short rhymes so that you can read as much or as little $ABC as you like, with lots of opportunities for joining in $5. Vibrant illustrations."
NewStr := RegExReplace(Str, ".*(?=\$[a-zA-Z]+)")
MsgBox, % NewStr

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 18:57

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 19:00

So once I have that piece of multi-line string on my clipboard, then when I run the following, it didn't do anything: -

clipboard := RegExReplace(clipboard, ".*(?=\$[a-zA-Z]+)")

Is this incorrect pls?

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 24 May 2022, 19:42

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 24 May 2022, 21:46

You need to use the s) option so that the . matches newline characters:

Code: Select all

Clipboard := RegExReplace(Clipboard, "s).*(?=\$[a-zA-Z]+)")

Btw, there's no need to keep posting the same thing several times with no new information. Please be patient.

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 25 May 2022, 15:21

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences  Topic is solved

Post by boiler » 25 May 2022, 15:35

Code: Select all

Clipboard := RegExReplace(Clipboard, "s).*?(\$[a-zA-Z]+)", "$1",, 1)

fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Re: Extracting item price out of sentences

Post by fivefive » 25 May 2022, 16:50

Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Extracting item price out of sentences

Post by boiler » 25 May 2022, 18:07

It refers to the first sub-pattern, which is the first parentheses grouping in the RegExPattern. So in the replacement string, where you see $1 gets replaced with whatever matched in that first parentheses grouping (the only one in this case).

Post Reply

Return to “Ask for Help (v1)”