Hello,
Can anyone help me to extract these 6 numbers separetly (from notepad .txt), they are inside variable and between each of them are 6-15 space places (with no rules for space places).
I need them in 6 variables.
4.364 4.379 22 9,598090 7 0,052000
Thank you.
Regex or similar divide variable Topic is solved
Re: Regex or similar divide variable
It will be easier if it looks like this.
4.364ssssssss4.379ssssssss22sssssssssssssssss9,598090sssss7ssssssssssssssssssssssss0,052000
4.364ssssssss4.379ssssssss22sssssssssssssssss9,598090sssss7ssssssssssssssssssssssss0,052000
Re: Regex or similar divide variable
Try this
Code: Select all
data := "4.364 4.379 22 9,598090 7 0,052000"
cur_pos := 1
numbers := []
While(RegExMatch(data, "O)(\d+\.\d+|\d+\,\d+|\d+)", numb, cur_pos)) {
cur_pos := numb.Pos(1) + numb.Len(1)
numbers.Insert(numb.Value(1))
}
loop, % numbers.Maxindex() {
MsgBox, % numbers[a_index]
}
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: Regex or similar divide variable
Wow!
Odlanir this is it.
Thank you very much.
Odlanir this is it.
Thank you very much.
Re: Regex or similar divide variable
Odlanir, please one more question.
If I want extract also letters and numbers or just letters, what will be different?
Lets say that in that varable instead of 22 is GHT22.
If I want extract also letters and numbers or just letters, what will be different?
Lets say that in that varable instead of 22 is GHT22.
Re: Regex or similar divide variable
could be surely better coded by a Regex guru but this should works.
Code: Select all
While(RegExMatch(data, "O)([A-Za-z]*\d+\.\d+|[A-Za-z]*\d+\,\d+|[A-Za-z]*\d+)", numb, cur_pos)) {
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: Regex or similar divide variable
Yes, yes!
Thank you again
Thank you again
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Regex or similar divide variable
Code: Select all
data := "4.364 4.379 22 9,598090 7 0,052000"
numbers := []
while RegExMatch(data, "O)[\d\.,]+", num, A_Index = 1 ? 1 : num.Pos + num.Len)
numbers.Push(num[0])
for k, v in numbers
MsgBox, % v
Re: Regex or similar divide variable Topic is solved
For something like this I would replace multiple spaces with single spaces, and then use StrSplit, or use a parsing loop.
Code: Select all
q::
vText := "4.364 4.379 22 9,598090 7 0,052000"
MsgBox, % vText
vText := RegExReplace(vText, " \K +")
MsgBox, % vText
;you could trim leading/trailing spaces also
vText := Trim(vText)
;to an array
oArray := StrSplit(vText, " ")
MsgBox, % oArray.1 " " oArray.6
;to variables
Loop, Parse, vText, % " "
v%A_Index% := A_LoopField
MsgBox, % v1 " " v6
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Regex or similar divide variable
Guys thanks you all, every answer is exellent.
Ofcourse jeeswg is the master in ahk, logic is great and step by step explanation.
Ofcourse jeeswg is the master in ahk, logic is great and step by step explanation.
Re: Regex or similar divide variable
Also, arr:=strsplit(regexreplace(data,"\s+","|"),"|"), example,
Cheers.
Code: Select all
; Input
data := "4.364 4.379 22 9,598090 7 0,052000"
arr:=strsplit(regexreplace(data,"\s+","|"),"|") ; Replace any sequence of white space with |, and split the resulting |-delimited string into an array
; Show the result:
for k, num in arr
str .= "arr[" k "]" "`t=`t" num "`n"
msgbox % str
Re: Regex or similar divide variable
hahah, yes i saw
Thank you Helgef
Thank you Helgef
Re: Regex or similar divide variable
@ noname,
@ jeeswg, I'd use stringsplit rather than the loop if I wanted variables. Good thinking about the trim though
@ hrvoje83, np
Cheers
@ jeeswg, I'd use stringsplit rather than the loop if I wanted variables. Good thinking about the trim though
@ hrvoje83, np
Cheers
Re: Regex or similar divide variable
Hi all,
One problem.. in message box everything looks fine.
Lest say first number is 4.364, but when I am put this variable into excel it looks like this 2,364 and that is complety different number.
result is 2,364 - this is wrong
How to solve that?
One problem.. in message box everything looks fine.
Lest say first number is 4.364, but when I am put this variable into excel it looks like this 2,364 and that is complety different number.
Code: Select all
XL.Range("A1").Value := v1
How to solve that?
Re: Regex or similar divide variable
I mean result is 4,364 also wrong
Re: Regex or similar divide variable
Removing the dots will that solve it ?
btw 4.364 does that mean four thousand three hundred sixty four ? ( in your country notation)
btw 4.364 does that mean four thousand three hundred sixty four ? ( in your country notation)
Code: Select all
; Input
data := "4.364 4.379 22 9,598090 7 0,052000"
arr:=strsplit(regexreplace(strReplace(data,"."),"\s+","|"),"|") ; Replace any sequence of white space with |, and split the resulting |-delimited string into an array
; Show the result:
for k, num in arr
str .= "arr[" k "]" "`t=`t" num "`n"
msgbox % str
Re: Regex or similar divide variable
Ni noname,
Sorry I was away for two days.
Yes good thinking, first to replate dots. Thanks.
Thats right, in my country this is 4.000 four thousand.
Sorry I was away for two days.
Yes good thinking, first to replate dots. Thanks.
Thats right, in my country this is 4.000 four thousand.
Who is online
Users browsing this forum: Google [Bot], Rohwedder and 205 guests