python - How can I extract English characters from a string of mixed (Arabic and English) Letters
问题描述
I have many strings similar as below
"A ali - عالي"
"Baghdad - بغداد"
I want to extract "A ali", "Baghdad" out of this using python but not splitting based on "-".
Please help.
解决方案
使用正则表达式。
前任:
import re
s = """A ali - عالي
Baghdad - بغداد"""
for line in s.splitlines():
m = re.search(r"([A-Za-z\s]+)", line)
if m:
print(m.group(1))
输出:
A ali
Baghdad
推荐阅读
- javascript - 为什么onClick删除react.js中redux数组中的所有项目?
- ubuntu - Ubuntu文件服务器的性能问题
- r - R:不包含在 HTML 中的 Webscraping 数据
- c# - 在 WebBrowser 控件中获取 HTML CheckBox 状态
- reactjs - 为什么我的模式没有出现在 react native iOS 中。但它在反应原生android中工作
- python - 在每个 URL 中创建一个新的 todolist 实例
- angular - TypeError: Jest: 转换必须导出一个 `process` 函数
- c# - C# - 通用事件处理程序,用于移动在运行时使用鼠标创建的图片框
- c - C中的算术异常
- python-3.x - 在每个项目的 PyCharm 中设置 PYTHONPATH