Hey guys,
Hope all is well. I have a favour to ask! Basically, I got a list product code in letters and they go like this: -
Purchased A B C D on First Monday in June
Purchased B B B on First Tuesday in July
Purchased C C C C on Second Monday in August
Purchased D D D D on Third Monday in September
Purchased E E E on Fourth Monday in September
I would like to extract if possible: -
ABCD
BBB
CCCC
DDDD
EEE
Please note: -
The product codes could be 3 or 4 letters long.
Any idea please? I would be really grateful!
Many thanks
Extracting upper cases ?
Re: Extracting upper cases ?
Code: Select all
#Requires AutoHotkey v1.1.33
str := "
(
Purchased A B C D on First Monday in June
Purchased B B B on First Tuesday in July
Purchased C C C C on Second Monday in August
Purchased D D D D on Third Monday in September
I Purchased E E E on Fourth Monday in September
I Purchased E E E on Fourth Monday in September
I Purchased EEE on Fourth Monday in September
I Purchased EE E on Fourth Monday in September
Purchased F F on Fifth Monday in September
Purchased g g g on Sixth Monday in September
)"
MsgBox % prodCodes(str)
prodCodes(str) {
Static regex := "([A-Z] *){3,4}"
Loop Parse, % str, `n, `r
RegExMatch(A_LoopField, regex, m), out .= RegExReplace(m, "\h+") "`n"
Return Trim(out, "`n")
}
Re: Extracting upper cases ?
Thanks a lot for your help! Actually, just thought another issue: -mikeyww wrote: ↑25 Apr 2023, 10:19Code: Select all
#Requires AutoHotkey v1.1.33 str := " ( Purchased A B C D on First Monday in June Purchased B B B on First Tuesday in July Purchased C C C C on Second Monday in August Purchased D D D D on Third Monday in September I Purchased E E E on Fourth Monday in September I Purchased E E E on Fourth Monday in September I Purchased EEE on Fourth Monday in September I Purchased EE E on Fourth Monday in September Purchased F F on Fifth Monday in September Purchased g g g on Sixth Monday in September )" MsgBox % prodCodes(str) prodCodes(str) { Static regex := "([A-Z] *){3,4}" Loop Parse, % str, `n, `r RegExMatch(A_LoopField, regex, m), out .= RegExReplace(m, "\h+") "`n" Return Trim(out, "`n") }
I Purchased EEE On Fourth Monday in September
In this case, it would return "EEEO", any way to get rid of the O please? (If On has the O in uppercase)
I would be really grateful! Many thanks
Re: Extracting upper cases ?
We have reached the "That works, but what if...?" part of the tutorial!
Show all of your relevant examples, and describe a rule that you would like to use to distinguish matches from non-matches. We can then pursue a solution once instead of many times.
Show all of your relevant examples, and describe a rule that you would like to use to distinguish matches from non-matches. We can then pursue a solution once instead of many times.
Re: Extracting upper cases ?
Thanks very much!! Sorry about this. This would be the last criteria: -
So if they contain E E E This
Then it currently generates EEET instead of EEE that is needed.
I would be really grateful! Many thanks!
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Extracting upper cases ?
just add \b
Code: Select all
prodCodes(str) {
Static regex := "([A-Z] *){3,4}\b"
Loop Parse, % str, `n, `r
RegExMatch(A_LoopField, regex, m), out .= RegExReplace(m, "\h+") "`n"
Return Trim(out, "`n")
}
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Nick Riviera and 87 guests