From a487804c49eae8477730cf586081dda0a99da36c Mon Sep 17 00:00:00 2001 From: Ali Jafari <50498845+alijafari79@users.noreply.github.com> Date: Thu, 3 Nov 2022 00:06:22 +0330 Subject: [PATCH] Create find_num.py --- Python/find_num.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Python/find_num.py diff --git a/Python/find_num.py b/Python/find_num.py new file mode 100644 index 0000000..d7b428c --- /dev/null +++ b/Python/find_num.py @@ -0,0 +1,20 @@ +# Find Numbers in a String : + +# Python3 code to demonstrate +# getting numbers from string +# using re.findall() +import re + +# initializing string +test_string = "There are 2 apples for 4 persons" + +# printing original string +print("The original string : " + test_string) + +# using re.findall() +# getting numbers from string +temp = re.findall(r'\d+', test_string) +res = list(map(int, temp)) + +# print result +print("The numbers list is : " + str(res))