Oct-09-2019, 11:53 PM
(This post was last modified: Oct-09-2019, 11:53 PM by newbieAuggie2019.)
(Oct-09-2019, 07:45 PM)tantony Wrote: @snippsat, thanks that worked. So just to make sure, there's no way to get just the integers from my original regex?k = re.findall("FEW\d+|SCT\d+|BKN\d+|OVC\d+", w)With my original regex, I was gettingQuote:['BKN022', 'BKN040', 'OVC001', 'FEW070', 'SCT080']
(Oct-09-2019, 10:27 PM)stullis Wrote: The "?:" in the capture group changes it to a non-capturing group. So "(?:FEW|SCT|BKN|OVC)(\d{3})" would result in only the numbers. From what you posted, it looks like you compiled the regex using my code but didn't use it to match anything.
Hi!
I think that sometimes, newbies like myself, don't get straightaway what the experienced programmers here unselfishly and kindly provide as answers and advice.
Maybe, if you are also a newbie, you didn't realize that Stullis was also pointing you out another solution, although you had to do the necessary adjustments. Here I'll show you what I think he meant (regex1), comparing it with what you had before (k):
import re w = 'KTPA 081653Z 00000KT 10SM BKN022TCU BKN040 OVC001RMK 28/23 A2990 FEW070 RMK AO2 SLP125 TCU SCT080 NW-NE T02830228' k = re.findall("FEW\d+|SCT\d+|BKN\d+|OVC\d+", w) regex1 = re.findall("(?:FEW|BKN|OVC|SCT)(\d{3})", w) print(k) print(regex1)and that produces the following output:
Output:['BKN022', 'BKN040', 'OVC001', 'FEW070', 'SCT080']
['022', '040', '001', '070', '080']
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs