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 split chinese and english word once only?

I am using Python and I would like to split the following string:

string = '小西 - 杏花 Siu Sai - Heng Fa'

I would like to split the string that could give me 小西 - 杏花 and Siu Sai - Heng Fa. I tried different ways and still couldn’t split the string properly.

Thanks in advance

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

>Solution :

One of the option is just to split before the first English character and take the 1st and 2nd group

inputstring = '小西 - 杏花 Siu Sai - Heng Fa'
a = re.split(r'([a-zA-Z].*)', inputstring)
>>>['小西 - 杏花 ', 'Siu Sai - Heng Fa', '']
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