假设我有这个正则表达式
[0-9 ]{5,7}
我在用python
import re
re.search(r'[0-9 ]{5,7}', '1123124213')
这将为此返回一个正值
但是,如果我用
re.match(r'[0-9 ]{5,7}', '1123124213')
但是,我的字符串通常是这样的:
I am going home tonight call me at 21314123
标记化也不起作用。如何解决此问题
我想配这个
I am going home tonight call me at 21314
但不是
I am going home tonight call me at 21314123
但是,如果我使用regex,我将能够同时搜索21314
和21314123
基本上我有一个包含这些字符串的字符串列表
I am going home tonight call me at 213123
I am going home tonight call me at 21313
I am going home tonight call me at 2131
I am going home tonight call me at 21314213123
I am going home tonight call me at 21314
我想使用regex/任何方法来提取那些包含
I am going home tonight call me at 21314
re.search
将在字符串中的任何位置找到您的模式,而re.match
将只在开头找到它。因此,对于示例字符串,re.match
不会返回值相关问题 更多 >
编程相关推荐