How too extract numbers between parentheses and strings comma separated Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xinxilas
Posts: 30
Joined: 18 Nov 2015, 16:54

How too extract numbers between parentheses and strings comma separated

16 Mar 2018, 18:23

Can anyone help me to Extract numbers between parentheses on google datasheet?

I have theese:
Bacacheri, Curitiba (82515280), Paraná

I want to extract the Number 82515280

Annd need to extract
"Bacacheri" First string before comma
"Curitiba" Second string before comma but wihtout (82515280)
"Paraná", Third string after commas
Rohwedder
Posts: 7631
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 02:03

Hallo,
try:

Code: Select all

Text = Bacacheri, Curitiba (82515280), Paraná
Loop, Parse, Text, CSV
{
	Text%A_Index% := Trim(RegExReplace(A_LoopField, "[0-9()]",""))
	Number%A_Index% := Trim(RegExReplace(A_LoopField, "[^0-9]",""))
}
MsgBox, % "Text1: " Text1
MsgBox, % "Text2: " Text2
MsgBox, % "Number2: " Number2
MsgBox, % "Text3: " Text3
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 04:04

And replace Text = Bacacheri, Curitiba (82515280), Paraná with Text = ClipBoard when you're on the data sheet. You will have to copy to cliboard.
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 04:18

Non regex example for something different:

Code: Select all

String := "Bacacheri, Curitiba (82515280), Paraná"

Loop, Parse, String, CSV, %A_Space%
{
    if (A_Index = 1)
        Col1 := A_LoopField
    else if (A_Index = 2)
        Loop, Parse, A_LoopField, %A_Space%,()
            (A_Index = 1) ? Col2 := A_LoopField : Col3 := A_LoopField
    else
        Col4 := A_LoopField
}

MsgBox % Col1 . "`n"
       . Col2 . "`n"
       . Col3 . "`n"
       . Col4
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 04:31

Another way:

Code: Select all

Text = Bacacheri, Curitiba (82515280), Paraná
while RegExMatch(Text, "O)[\d\w\p{L}]+", w, A_Index = 1 ? 1 : w.Pos + w.Len)
	str .= w.value "`n"
msgbox % str
Last edited by Odlanir on 17 Mar 2018, 04:47, edited 1 time in total.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How too extract numbers between parentheses and strings comma separated  Topic is solved

17 Mar 2018, 04:40

Two ideas.

Code: Select all

q:: ;split text
vText := "Bacacheri, Curitiba (82515280), Paraná"
RegExMatch(vText, "O)^(.*?), (.*?) \((\d*)\), (.*)$", oMatch)
MsgBox, % oMatch.1 "|" oMatch.2 "|" oMatch.3 "|" oMatch.4

;using StrSplit
vText := "Bacacheri, Curitiba (82515280), Paraná"
oArray := StrSplit(vText, ", ")
MsgBox, % oArray.1 "|" oArray.2 "|" oArray.3
RegExMatch(oArray.2, "O)^(.*?) \((\d*)\)$", oMatch)
MsgBox, % oArray.1 "|" oMatch.1 "|" oMatch.2 "|" oArray.3
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 05:52

strsplit() only:

Code: Select all

String :="Bacacheri, Curitiba (82515280), Paraná"

col:=strsplit(string, a_space , "`,()")

MsgBox % Col.1 . "`n"
       . Col.2 . "`n"
       . Col.3 . "`n"
       . Col.4
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 06:36

@ SpeedMaster :o :shock: :thumbup:

Another attempt ...

Code: Select all

test := "Bacacheri, Curitiba (82515280), Paraná"
Col := StrSplit(StrReplace(StrReplace(test,"(",","),")",","),",", " ")
MsgBox % Col[1] " " Col[2] " " Col[5]
xinxilas
Posts: 30
Joined: 18 Nov 2015, 16:54

Re: How too extract numbers between parentheses and strings comma separated

17 Mar 2018, 08:18

Thank you very much, all ways worked, ill choose the best for me right now

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 246 guests