RegEx pros needed! Shorten this code? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

RegEx pros needed! Shorten this code?

Post by Krd » 04 Feb 2023, 08:42

Hey!

This works for my use after scraping the internet and forums to put this together:

Code: Select all

F1::
Mystring =
(
Mars soon 3331,00 
dgf 0123456 


wordy

digit 1234,00  
another digit -1234,00 
Mars 3334,01
 Sun

Univers -4321,00  

)
RegExMatch(MyString,"s)Mars first(.*)Sun",Earth)
RegExMatch(MyString,"s)Mars(.*)Sun",Earth)
Earth := RegExReplace(Earth, "\,.*")
Earth := RegExReplace(Earth, "\D")
MsgBox, % Earth
return
I am looking for match in line 12, but only the digits 3334,01 in this example (Can be 0,00 to 1000000,99).

In line 19 I could not jump over line 18. How to skip line 18? Cecause first match has another word behind it before a digit exists which I don't want to catch.
And in line 20 I remove decimals first before having the digits I want. :crazy:

I know all these 4 lines can be 1. But I know that I can not do that myself.

Anyone pros? :D

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: RegEx pros needed! Shorten this code?  Topic is solved

Post by mikeyww » 04 Feb 2023, 08:52

Code: Select all

RegExMatch(str, "Mars\h*\K[\d,]+", number)
; RegExMatch(str, "Mars\h*\K[\d]+", number)
MsgBox 64, Result, % number

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: RegEx pros needed! Shorten this code?

Post by Krd » 04 Feb 2023, 12:09

Code reduced with 75%!

Thanks for providing with and without decimals, which was the last one I actually wanted!

Much appreciated mikey!

:bravo:

Post Reply

Return to “Ask for Help (v1)”