[英]Find a number+word with regex python
I want to select a number concatenate with a word in a text.我想 select 一个数字与文本中的单词连接。
Example:例子:
text = I want to find 123456R
I tried with ref = re.findall('[0-9]+', text)
我试过ref = re.findall('[0-9]+', text)
but it returns me only 123456
, while I want 123456R
.但它只返回123456
,而我想要123456R
。
Anyone have an idea to select a number+word?有人对 select 有一个数字+单词的想法吗?
Your expression matches only numbers one or more times, whereas you need to match a group of numbers followed by one letter.您的表达式只匹配数字一次或多次,而您需要匹配一组数字后跟一个字母。 You can do this by appending a letter group after the number group:您可以通过在数字组后附加一个字母组来做到这一点:
ref = re.findall('[0-9]+[A-Za-z]', text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.