Finding the number between two words in a text - RegEx

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Injuste
Posts: 5
Joined: 23 Jul 2018, 06:42

Finding the number between two words in a text - RegEx

23 Jul 2018, 08:04

Code: Select all

text := "this 54.8 is a 51 test 88888888888.1 hehe"

RegExReplace(text, "[\d.]+", output)
msgbox, %output%
How do I get the 88888888888.1 from the text? It will have less and more digits sometimes.
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 08:55

Hallo,
do you want this?:

Code: Select all

#SingleInstance, Force
text := "this 54.8 is a 51 test 88888888888.1 hehe"

output := RegExReplace(text, "[^\d.]+", " ")
msgbox, %output%
Injuste
Posts: 5
Joined: 23 Jul 2018, 06:42

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 09:04

Rohwedder wrote:Hallo,
do you want this?:

Code: Select all

#SingleInstance, Force
text := "this 54.8 is a 51 test 88888888888.1 hehe"

output := RegExReplace(text, "[^\d.]+", " ")
msgbox, %output%
Wow it's awesome thank you but I don't need all of them, I just need to get 88888888888.1 from it. Since it's between two words.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 09:15

If the two word are always the same you could do this "(?<=Test )[^\d.]+(?= hehe)"
Injuste
Posts: 5
Joined: 23 Jul 2018, 06:42

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 09:21

MannyKSoSo wrote:If the two word are always the same you could do this "(?<=Test )[^\d.]+(?= hehe)"

Code: Select all

text := "this 54.8 is a 51 test 88888888888.1 hehe"

RegExMatch(text, "(?<=test )[^\d.]+(?= hehe)", output)
msgbox, %output%
Doesn't work, message box pops up empty. I guess I did something wrong with syntax, can you try and put a simple code?

Thank you.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 09:35

text := "this 54.8 is a 51 test 88888888888.1 hehe"
RegExMatch(text, "(?<=test\s)\d+\.?\d+?", output)
msgbox, %output%
Injuste
Posts: 5
Joined: 23 Jul 2018, 06:42

Re: Finding the number between two words in a text - RegEx

23 Jul 2018, 09:38

MannyKSoSo wrote:

Code: Select all

text := "this 54.8 is a 51 test 88888888888.1 hehe"
RegExMatch(text, "(?<=test\s)\d+\.?\d+?", output)
msgbox, %output%
Oh got it, it works. Thanks a lot. Problem solved.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Lamron750, mikeyww and 235 guests