如何从匹配对象中删除角色?

2024-09-29 23:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

一些数据包含一个额外的空白,我想去掉它,但不幸的是,在这一点上,它是一个匹配对象,所以我如何删除它

for string in sl:
    for keyword in keywordList: #looping through each string in syslog.txt against each keyword in keyword.txt
        if keyword in string:

        hostnameResult = re.search(r"\s[A-z]+\s", string)

        dateResult = re.search(r"^[A-Z][a-z][a-z]\s\s[0-9]+\s[0-9]{2}\:[0-9]{2}\:[0-9]{2}", string)

        del(dateResult[3]) <- the part I'm trying to actually do.

        print "**"+keyword+"**"+hostnameResult.group(0)+dateResult.group(0)

Tags: 数据对象inretxtforsearchstring

热门问题