Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用正则表达式打印提取的子字符串会导致&书信电报;内置函数id>&引用;_Python_Regex_String - Fatal编程技术网

Python 使用正则表达式打印提取的子字符串会导致&书信电报;内置函数id>&引用;

Python 使用正则表达式打印提取的子字符串会导致&书信电报;内置函数id>&引用;,python,regex,string,Python,Regex,String,我在查找如何从一个强函数中提取子字符串时,遇到了StackOverflow上发布的问题。这是我只想从中提取数字的列表集(即从'ID:39'中提取'39'): 我必须这样做的代码基于上面的链接帖子: id_uncleaned = name_id_list[1] found = re.search('\(ID: (\d*)\)', id_uncleaned) if found: id = found.group(1) print(id) 但是当我试图打印它时,它返回了一个。这是为什么

我在查找如何从一个强函数中提取子字符串时,遇到了StackOverflow上发布的问题。这是我只想从中提取数字的列表集(即从'ID:39'中提取'39'):

我必须这样做的代码基于上面的链接帖子:

id_uncleaned = name_id_list[1]

found = re.search('\(ID: (\d*)\)', id_uncleaned)

if found:
    id = found.group(1)

print(id)

但是当我试图打印它时,它返回了一个
。这是为什么?我如何从'39'等中获取数字?

id是Python的一个内部函数。如果found未设置为值,则不会出现行
id=found.group(1)
,因此当您打印(id)时,您将获得其原始值。
避免使用id作为变量的名称,这样会更清晰。

尝试以下表达式:
found=re.search('id:(\d*)\),id\u uncleaned)
@ferhen,谢谢!这就解决了问题。@MenglongLi
id
id_uncleaned = name_id_list[1]

found = re.search('\(ID: (\d*)\)', id_uncleaned)

if found:
    id = found.group(1)

print(id)