我不太清楚这里发生了什么。根据我的理解,。*应该匹配我在此处设置的所有内容,除了换行符。如果我添加一个匹配。或\ n,它匹配\ n一次,并忽略字符串的其余部分。
代码:
import re
regex="(network=\{\\n\\tid=[\"|\']+identificationInformation+[\"|\'][.|\\n]*)"
contents = re.sub(regex,replacementString,contents)
print contents
打印输出:
information={(contents of replacementString)
}
(everything after the line containing 'id')
答案 0 :(得分:0)
它需要的是:
regex="(network=\{\\n\\tid=[\"|\']+identificationInformation+[\"|\'](.|\\n)*)"
尝试用.*
解决它是行不通的,因为它与换行符不匹配。
尝试使用[.]*
或[.|\\n]*
解决问题是行不通的,因为这样会使.
与@ user2357112提到的文字相匹配。
我需要使用我之前必须忽略的(.|\\n)*
。