python - 在特殊字符 Python RegEx 之后获取字符串
问题描述
如何在特殊字符后获取字符串?
例如我想在/
in之后获取字符串
my_string = "Python/RegEx"
输出为:RegEx
我试过了 :
h = []
a = [ 'Python1/RegEx1' , 'Python2/RegEx2', 'Python3/RegEx3']
for i in a:
h.append(re.findall(r'/(\w+)', i))
print(h)
但输出是:[['RegEx1'], ['RegEx2'], ['RegEx3']]
我需要 :['RegEx1', 'RegEx2', 'RegEx3']
提前致谢
正则表达式初学者
解决方案
使用.extend()
:
for i in a:
h.extend(re.findall(r'/(\w+)', i))
使用+=
(只是另一种调用方式.extend
):
for i in a:
h += re.findall(r'/(\w+)', i)
使用解包:
for i in a:
h.append(*re.findall(r'/(\w+)', i))
推荐阅读
- amazon-web-services - 在 AWS Amplify REST API (Javascript) 中使用路径参数
- mysql - .Net Core docker 容器无法连接到 MySQL docker 容器
- javascript - 从数据库中获取数据的动态下拉列表不起作用
- rtos - TI ROTS BIOS 设置 semaphore() 函数错误
- reactjs - 为什么当 componentShouldUpdate 返回 true 时我的 react 组件不会重新渲染?
- python - 如何连接熊猫中的子字符串
- nginx - 将自定义的固定标头传递给 nginx 中的 auth_request
- php - 从 IP 地址或 PHP 中的纬度/经度获取邮政编码
- php - 使用购买令牌对 Playstore 应用内购买实施收据验证
- mysql - 如何根据条件删除结果以计算平均值