简体   繁体   English

正则表达式删除所有数字和特殊字符,但空格和字母

[英]Regex to strip all numbers and special characters but space and letters

Can someone help me out with the regular expression to strip a string like this -> 有人可以用正则表达式帮我解开像这样的字符串 - >

      '226710': 'Kevin Werbach'

to obtain just --> Kevin Werbach 只获得 - > Kevin Werbach

My attempt --> 我的尝试 - >

   instructors = re.sub(r'([^a-zA-Z\s]+?)', '', instructors)

which returned --> 返回 - >

  KevinWerbach  

without any space between. 没有任何空间。

This works: 这有效:

import re
text = "'226710': 'Kevin Werbach'"
print(re.sub (r'([^a-zA-Z ]+?)', '', text))

You can also change the space to \\s: 您还可以将空间更改为\\ s:

print(re.sub (r'([^a-zA-Z\s]+?)', '', text))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式:获取以特定字母开头的所有数字和特殊字符,当数字后出现空格时停止 - Regex: get all numeric and special characters starting with specific letters, stop when space occurs after number 正则表达式验证字符串包含字母和数字而不考虑特殊字符 - Regex validate string contains letters and numbers regardless of special characters 正则表达式:特殊字符之间的数字(但不是所有数字) - Regex: Numbers between special characters (but not all number) 正则表达式:删除字母之间不是撇号的所有特殊字符 - Regex: Remove all special characters that are not apostrophes between letters 正则表达式提取具有不同长度和特殊字符的所有数字 - regex to extract all numbers with different lengths and special characters Python 正则表达式:删除所有未附加到单词的特殊字符和数字 - Python regex: removing all special characters and numbers NOT attached to words 重新搜索贪婪匹配所有组合(字母,特殊字符,数字) - re.search greedy matching all combinations (letters, special characters, numbers) 正则表达式匹配字母,数字和一些特定字符? - Regex to match letters, numbers and some specific characters? 正则表达式获取包含字母和(数字/某些特殊)的“单词”,但不仅仅是数字 - regex to get “words” containing letters and (numbers/certain special), but not only numbers 正则表达式匹配除数字和特殊字符以外的所有内容 - Regex match everything except numbers and special characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM