Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove english letter between non english letter?

I have list of string, and I want to filter out non English character from string.

list=['ಎಮ್ ರಾಮಲಿಂಗ ರೆಡ್ಡಿ, from the ಮನೆ ಸಂಖ್ಯೆ  M Ramalinga Reddy,
      '23/2 ವಾರ್ಡ್ ಸಂಖ್ಯೆ 18, 1ನೇ ಅಡ್ಡ ರಸ್ತೆ, 23/2 Ward No 18, Cross,']

My code:

regex = re.compile("[^a-zA-Z0-9!@#$&()\\-`.+,/\"]+")
for i in list:
   li = regex.sub(' ', i)
   print(li)

My output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[, from the M Ramalinga Reddy,
23/2 18, 1 , 23/2 Ward No 18, Cross,]

My desire output

[M Ramalinga Reddy,
23/2 Ward No 18, Cross]

>Solution :

Assuming we phrase your problem as finding the final English language words in each string in the list, we can try using re.findall here:

# -*- coding: utf-8 -*-

import re
inp = ['ಎಮ್ ರಾಮಲಿಂಗ ರೆಡ್ಡಿ, from the ಮನೆ ಸಂಖ್ಯೆ  M Ramalinga Reddy, D No',
  '23/2 ವಾರ್ಡ್ ಸಂಖ್ಯೆ 18, 1ನೇ ಅಡ್ಡ ರಸ್ತೆ, 23/2 Ward No 18, fst Cross,']
output = [re.findall(r'[a-zA-Z0-9"/]+(?: [a-zA-Z0-9!@#$&()\\-`.+,/\"]+)*$', x) for x in inp]
print(output)
# ['M Ramalinga Reddy, D No', '23/2 Ward No 18, fst Cross,']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading