Python Forum
Python regex to get only numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python regex to get only numbers
#4
(Oct-09-2019, 06:57 PM)tantony Wrote: How can I get only the integers from this?
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|SCT|BKN|OVC)(\d{3})", w)
lst = [int(i[1]) for i in k]
print(lst)
Output:
[22, 40, 1, 70, 80]
Reply


Messages In This Thread
Python regex to get only numbers - by tantony - Oct-09-2019, 04:39 PM
RE: Python regex to get only numbers - by stullis - Oct-09-2019, 05:12 PM
RE: Python regex to get only numbers - by tantony - Oct-09-2019, 06:57 PM
RE: Python regex to get only numbers - by snippsat - Oct-09-2019, 07:21 PM
RE: Python regex to get only numbers - by tantony - Oct-09-2019, 07:45 PM
RE: Python regex to get only numbers - by stullis - Oct-09-2019, 10:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Regex quest 2 2,425 Sep-22-2022, 03:15 AM
Last Post: quest
  Find numbers using Regex giddyhead 18 3,282 Jul-28-2022, 12:29 AM
Last Post: giddyhead
  python regex: get rid of double dot wardancer84 4 2,428 Sep-09-2021, 03:03 PM
Last Post: wardancer84
  Using Regex Expression With Isin in Python eddywinch82 0 2,323 Apr-04-2021, 06:25 PM
Last Post: eddywinch82
  Exception handling in regex using python ShruthiLS 1 2,389 May-04-2020, 08:12 AM
Last Post: anbu23
  Python the regex not getting any attributes sarath_unrelax 1 1,881 Dec-19-2019, 11:06 AM
Last Post: Larz60+
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,786 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020