Extract Python specific parts only

Asked 2 years ago, Updated 2 years ago, 47 views

import re


s = " 2019-11-22 5 people 010-1111-2222"
numbers = re.findall("\d+", s)
print(numbers)

Result value: ['2019', '11', '22', '5', '010', '1111', '2222'] Is there a way to make only 20191112 come out here?

python regex

2022-09-21 16:03

1 Answers

Is the value of the s variable always in that format? Why did you write "Findall"? It depends on the situation I don't know if you have to get the desired result using the values in the numbers, but if that's not the case, I think we can think of a way to separate the values in the s itself. s = "Date ="Date ="Date ""Person" by dividing "Date 번호"Person" "Number", phone_number = "Phone number" or something like that.


2022-09-21 16:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.