How to Use Regular expression to extract phone number

How to use server script and regular expression to extract phone number from address and paste into another field before insert preferably. I don’t know if RE or regex module is available, do we have to import it. I tried using system console to check but nothing.
I am using shared hosting of frappe cloud.

Can you please share the format or some example data?

This is an example address, we get in these formats.

h.No 111 , Bhagath Singh Lane Perumthanni Eanchakkal Road , Opposite to Dreams Stiching center Trivandrum
Kerala IN
695008
8592999345

9th cross, Thirumagal Nagar, Peelamedu pudur, Coimbatore, Tamil Nadu 641004,8592999345

Try this

import re
data = "9th cross, Thirumagal Nagar, Peelamedu pudur, Coimbatore, Tamil Nadu 641004,8592999345"

# Regular expression to match phone numbers (10 digits)
phone_numbers = re.findall(r'\b\d{10}\b', data)
print(phone_numbers)

I am getting error “Import


Error: import not found”
It is not able to import module I think.

I think python module import is not allowed in server scripts.

def extract_phone_numbers(data):
	phone_numbers = []
	words = data.split()

	for word in words:

		if word.isdigit() and len(word) == 10:
			phone_numbers.append(word)

	return phone_numbers
data = "9th cross, Thirumagal Nagar, Peelamedu pudur, Coimbatore, Tamil Nadu 641004,8592999345"
phone_numbers = extract_phone_numbers(data)

print(phone_numbers, "Phone number\n\n\n\n\nn\n")

Try this

Thanks,
This script worked for me, it is not perfect but filters 10 digit mobile number under limited formats

s = doc.primary_address
newstr = ''.join((ch if ch in '0123456789' else ' ') for ch in s)
listOfNumbers = [int(i) for i in newstr.split()]
for item in listOfNumbers:
    if item >1000000000 and item <9999999999:
        mob_no = str(item)
doc.mobile_no =mob_no