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
#1
I have the following script

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)
print(k)
When I run it, I'm getting
Quote:['BKN022', 'BKN040', 'OVC001', 'FEW070', 'SCT080']
, but I only want the integers from it so that it looks like this
Quote:['022', '040', '001', '070', '080']
. Once I get the integers, I can sort it to get the lowest number.

How would I do that?
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,474 Sep-22-2022, 03:15 AM
Last Post: quest
  Find numbers using Regex giddyhead 18 3,351 Jul-28-2022, 12:29 AM
Last Post: giddyhead
  python regex: get rid of double dot wardancer84 4 2,444 Sep-09-2021, 03:03 PM
Last Post: wardancer84
  Using Regex Expression With Isin in Python eddywinch82 0 2,337 Apr-04-2021, 06:25 PM
Last Post: eddywinch82
  Exception handling in regex using python ShruthiLS 1 2,403 May-04-2020, 08:12 AM
Last Post: anbu23
  Python the regex not getting any attributes sarath_unrelax 1 1,897 Dec-19-2019, 11:06 AM
Last Post: Larz60+
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,824 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