I have the following sentence in a wall of text where I want to extract an embedded variable dollar amount (could be 1 to 3 digits) between [... done for] and [USD (excl. tax) but...], so in the following case this number should be [50]. What would be the most efficient way to achieve this using RegEx or other methods?
...
text
text
text
Based on past jobs we think we can get this job done for 50 USD (excl. tax) but we are not set on this as we also want ...
text
text
text
...
RegEx to find variable dollar amount in a wall of text Topic is solved
RegEx to find variable dollar amount in a wall of text Topic is solved
Last edited by carno on 11 Oct 2017, 16:13, edited 1 time in total.
-
- Posts: 162
- Joined: 12 Apr 2017, 23:03
Re: RegEx to find variable dollar amount in a wall of text
I'm just learning RegExMatch but this is what I figured out so far. Probably a more efficient way yet hopefully someone can school us both!
If its not working with a particular block of text please provide that example.
In the block of text I've included within %note% I've added various numbers and several occurences of the amount to find.
I've tested with between 1 and 6 digits preceding USD.
Code: Select all
note=
(
...
stuff here blah blahblhablhablah sklchsldkn klcnaslnk 2345 34 5 333
Based on past jobs we think we can get this job done for 5 USD (excl. tax) but we are not set on this as we also want ...
Based on past jobs we think we can get this job done for 20 USD (excl. tax) but we are not set on this as we also want ...
textBased on past jobs we think we can get this job done for 75 USD (excl. tax) but we are not set on this as we also want ...
textBased on past jobs we think we can get this job done for 500 USD (excl. tax) but we are not set on this as we also want ...
text
text
...
)
vars:=[]
a:=0
while(a<strsplit(note).length()){
++a
if(RegExMatch(note, "\d+", var,a)>a)
a:=RegExMatch(note, "\d+ USD",var,a)
if(strsplit(var).length()>4)
++a
if(var)
vars[vars.length()+1]:=strsplit(var," ")[1]
}
for a, v in vars
msgbox, %v%
return
Edit * please see with object vars holding each number preceding USD.carno wrote:Hi, magicinmath, thanks for the effort, but this fails when I paste my wall of text. There are many other numerals before and after the sentence I highlighted in red (see above). I am seeking just the number (no USD) in that particular sentence I highlighted in red that is somewhere in the wall of text.
If its not working with a particular block of text please provide that example.
In the block of text I've included within %note% I've added various numbers and several occurences of the amount to find.
I've tested with between 1 and 6 digits preceding USD.
Last edited by magicinmath on 11 Oct 2017, 16:49, edited 4 times in total.
Re: RegEx to find variable dollar amount in a wall of text
Hi, magicinmath, thanks for the effort, but this fails when I paste my wall of text. There are many other numerals before and after the sentence I highlighted in red (see above). I am seeking just the number (no USD) in that particular sentence I highlighted in red that is somewhere in the wall of text.
PS: I added "StringTrimRight, v, v, 4" and now it works fine. (I had removed USD in "a:=RegExMatch(note, "\d+ USD",var,a)" and that is why it was failing.)
PS: I added "StringTrimRight, v, v, 4" and now it works fine. (I had removed USD in "a:=RegExMatch(note, "\d+ USD",var,a)" and that is why it was failing.)
Code: Select all
vars:=[]
a:=0
while(a<strsplit(note).length()){
++a
if(RegExMatch(note, "\d+ USD", var,a)>a)
a:=RegExMatch(note, "\d+ USD",var,a)
if(strsplit(var).length()>4)
++a
if(var)
vars[vars.length()+1]:=var
}
for a, v in vars
StringTrimRight, v, v, 4
msgbox, %v%
return
Re: RegEx to find variable dollar amount in a wall of text
Hi, magicinmath, thanks again, I had removed USD from "a:=RegExMatch(note, "\d+ USD",var,a)" and that is why it was failing. But now I analyzed you code in more detail and realized my error. Your code is working fine now and I appreciate your great work! This is the version of your code that works for me now ( ):magicinmath wrote:I'm just learning RegExMatch but this is what I figured out so far. Probably a more efficient way yet hopefully someone can school us both!
Code: Select all
note= ( ... stuff here blah blahblhablhablah sklchsldkn klcnaslnk 2345 34 5 333 Based on past jobs we think we can get this job done for 5 USD (excl. tax) but we are not set on this as we also want ... Based on past jobs we think we can get this job done for 20 USD (excl. tax) but we are not set on this as we also want ... textBased on past jobs we think we can get this job done for 75 USD (excl. tax) but we are not set on this as we also want ... textBased on past jobs we think we can get this job done for 500 USD (excl. tax) but we are not set on this as we also want ... text text ... ) vars:=[] a:=0 while(a<strsplit(note).length()){ ++a if(RegExMatch(note, "\d+", var,a)>a) a:=RegExMatch(note, "\d+ USD",var,a) if(strsplit(var).length()>4) ++a if(var) vars[vars.length()+1]:=strsplit(var," ")[1] } for a, v in vars msgbox, %v% return
Edit * please see with object vars holding each number preceding USD.carno wrote:Hi, magicinmath, thanks for the effort, but this fails when I paste my wall of text. There are many other numerals before and after the sentence I highlighted in red (see above). I am seeking just the number (no USD) in that particular sentence I highlighted in red that is somewhere in the wall of text.
If its not working with a particular block of text please provide that example.
In the block of text I've included within %note% I've added various numbers and several occurences of the amount to find.
I've tested with between 1 and 6 digits preceding USD.
Code: Select all
vars:=[]
a:=0
while(a<strsplit(note).length()){
++a
if(RegExMatch(note, "\d+ USD", var,a)>a)
a:=RegExMatch(note, "\d+ USD",var,a)
if(strsplit(var).length()>4)
++a
if(var)
vars[vars.length()+1]:=strsplit(var," ")[1]
}
for a, v in vars
msgbox, %v%
return
Who is online
Users browsing this forum: Google [Bot], Insanibaccha, PsysimSV and 203 guests