如何匹配字符串(字符串中含有“()”)

例如 Str = "Device Description: Intel(R) Imaging Signal Processor"
re.findall(r'(?i)Device Description: \s+({})'.format("Intel(R) Imaging Signal Processor"), Str)

这样匹配不到任何信息, 看起来是字符串中含有 "()" 影响了匹配, 如何解决?

将正则表达式中的括号用反斜杠转义

import re
Str = "Device Description: Intel(R) Imaging Signal Processor"
pattern = 'Device Description: {}'.format("Intel\(R\) Imaging Signal Processor")
print(Str)
print(pattern)
a=re.findall(pattern, Str)
if a:
    for i in a:
        print(i)

img



#-*- coding:utf-8 -*-
import re
Str = "Device Description: Intel(R) Imaging Signal Processor"
regx = re.compile( r'[\w\W\s]+.*?:\s([\w\W\s\(\)]+.*?)'  )
res = re.findall(regx, Str)
print(res)

r'(?i)Device Description: \s+({})'.format("Intel(R) Imaging Signal Processor"
的结果是
(?i)Device Description: \s+(Intel(R) Imaging Signal Processor)
你把后面的字符都扩起来是几个意思