Sep-24-2020, 07:32 AM
hi, I am not sure why my regex code is not working for finding Malaysian phone number, can anyone helps to check? would be highly appreciate. When I use .findall method, it won't appear any group in the list.
regex.findall that won't match anything
|
Sep-24-2020, 07:32 AM
hi, I am not sure why my regex code is not working for finding Malaysian phone number, can anyone helps to check? would be highly appreciate. When I use .findall method, it won't appear any group in the list.
If +60 is for Malaysia, then this should return a result:
import re regex = re.compile(r"\+60[0-9 ]+") # then regex.findall(BIG_TEXT_WITH_MANY_NUMBERS)If you need something with more functionality, you can look for https://pypi.org/project/phonenumbers/ It can parse phone numbers and you can access the country_code: import phonenumbers while True: phone_number = phonenumbers.parse(input("Phone number: ")) country_code = phone_number.country_code region = phonenumbers.region_code_for_country_code(country_code) print(country_code, region)A user tends to input invalid data. If phonenumbers have problems to parse a number, it will raise the NumberParseException . You can catch this.But this is only usable, if you know where the numbers are. If you want to scrape the web for phone numbers, you need a much better regex.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians! |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Facing issue in python regex newline match | Shr | 6 | 1,396 |
Oct-25-2023, 09:42 AM Last Post: Shr |
|
regex findall() returning weird result | Radical | 1 | 690 |
Oct-15-2023, 08:47 PM Last Post: snippsat |
|
Failing regex, space before and after the "match" | tester_V | 6 | 1,246 |
Mar-06-2023, 03:03 PM Last Post: deanhystad |
|
Regex pattern match | WJSwan | 2 | 1,322 |
Feb-07-2023, 04:52 AM Last Post: WJSwan |
|
Python: re.findall to find multiple instances don't work but search worked | Secret | 1 | 1,253 |
Aug-30-2022, 08:40 PM Last Post: deanhystad |
|
Match substring using regex | Pavel_47 | 6 | 1,488 |
Jul-18-2022, 07:46 AM Last Post: Pavel_47 |
|
Match key-value json,Regex | saam | 5 | 5,477 |
Dec-07-2021, 03:06 PM Last Post: saam |
|
Regex findall() | NewBeie | 2 | 4,341 |
Jul-10-2020, 12:19 PM Last Post: DeaD_EyE |
|
re.findall HELP!!! only returns None | Rusty | 10 | 7,115 |
Jun-20-2020, 12:13 AM Last Post: Rusty |
|
The "FindAll" Error | BadWhite | 6 | 4,486 |
Apr-11-2020, 05:59 PM Last Post: snippsat |