我有这个字符串(很明显,我从所有3条中删掉了几行,以免暴露自己)。 我想要python从中提取:
中级证书
键
公共证书
并将它们写入3个如上命名的单独文件中。
我正在尝试使用此正则表达式,但是它将所有这些都放在一起。
match1 = re.findall(r“中级证书((。| \ n)*)(----- END CERTIFICATE -----)”,strretret,re.MULTILINE)
(GetSecretResult){
Errors = ""
Secret =
(Secret){
Name = "new cert"
Items =
(ArrayOfSecretItem){
SecretItem[] =
(SecretItem){
Value = "new cert"
Id = 1470
FieldId = 334
FieldName = "E-Mail"
IsFile = False
IsNotes = False
IsPassword = False
FieldDisplayName = "E-Mail"
},
(SecretItem){
Value = "no password"
Id = 1471
FieldId = 335
FieldName = "Password"
IsFile = False
IsNotes = False
IsPassword = True
FieldDisplayName = "Password"
},
(SecretItem){
Value = None
Id = 1472
FieldId = 336
FieldName = "Account ID"
IsFile = False
IsNotes = False
IsPassword = False
FieldDisplayName = "Account ID"
},
(SecretItem){
Value = None
Id = 1473
FieldId = 337
FieldName = "Sign-in Link"
IsFile = False
IsNotes = False
IsPassword = False
FieldDisplayName = "Sign-in Link"
},
(SecretItem){
Value = "Intermediate cert
-----BEGIN CERTIFICATE-----
MIIEiTCCA3GgAwIBAgIQAlqK7xlvfg1sIQSyGuZwKzANBgkqhkiG9w0BAQsFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0xNzExMDYxMjIzNTJaFw0yNzExMDYxMjIzNTJaMFwxCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xGzAZBgNVBAMTElRoYXd0ZSBSU0EgQ0EgMjAxODCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBAMoIXuVTipccHkMvtoqnVumLhEOorJ16VY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1y4W
vXySQ7BvTxgxRTUIWRN+qPJK6UsmNU4HizBjktCjxq6xqBdE55jsda7hqDg=
-----END CERTIFICATE-----
"
Id = 147274
FieldId = 366
FieldName = "Notes"
IsFile = False
IsNotes = True
IsPassword = False
FieldDisplayName = "Notes"
},
}
Id = 31346
SecretTypeId = 6055
FolderId = 586
IsWebLauncher = False
Active = True
CheckOutMinutesRemaining = None
IsCheckedOut = None
CheckOutUserDisplayName = None
CheckOutUserId = None
IsOutOfSync = None
IsRestricted = False
OutOfSyncReason = None
}
}
答案 0 :(得分:0)
尝试以下正则表达式:(-----BEGIN .+?-----(?s).+?-----END .+?-----)
。您可以here进行尝试。这是通过在开始和结束之后进行延迟匹配,以及在两者之间进行延迟匹配来实现的。