Edited Topic is solved
Re: Extracting item price out of sentences
Code: Select all
Str := "Adam bought an orange @ $1.50-2.00"
RegExMatch(Str, "(?<=@ \$)[0-9.]+", Price)
MsgBox, % Price
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
I think for your purpose, it would be better to check that it's a number:
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.
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.
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
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:
You might need two else branches to handle all cases since the first could be true but not the other.
Code: Select all
If Price is number
if (Price > 0.01)
{
} Else
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
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
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
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?
clipboard := RegExReplace(clipboard, ".*(?=\$[a-zA-Z]+)")
Is this incorrect pls?
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
You need to use the s) option so that the . matches newline characters:
Btw, there's no need to keep posting the same thing several times with no new information. Please be patient.
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.
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences Topic is solved
Code: Select all
Clipboard := RegExReplace(Clipboard, "s).*?(\$[a-zA-Z]+)", "$1",, 1)
Re: Extracting item price out of sentences
Edited
Last edited by fivefive on 12 Mar 2023, 10:45, edited 1 time in total.
Re: Extracting item price out of sentences
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).