JSON字符串如下所示
{"data": [{
"id": "BankDetails.FirstName",
"value": "abcd",
"type": "Text"
},
{
"id": "BankDetails.AccountNumber",
"value": "12345678",
"type": "Text"
},
{
"id": "BankDetails.SortCode",
"value": "123",
"type": "Text"
}]
}
“ id”:“ BankDetails.AccountNumber”下的“ value”:“ 12345678”应替换为“ value”:“ ********”。我们如何为此编写正则表达式模式? 因此确切的输出将是
{"data": [{
"id": "BankDetails.FirstName",
"value": "abcd",
"type": "Text"
},
{
"id": "BankDetails.AccountNumber",
"value": "********",
"type": "Text"
},
{
"id": "BankDetails.SortCode",
"value": "123",
"type": "Text"
}]
}
注意:BankDetails.AccountNumber并不总是第三个对象。
答案 0 :(得分:1)
您可以使用可变宽度正向后视(C#支持)来定位每个数字,并使用此正则表达式将其替换为*
(?<="id": "BankDetails.AccountNumber",\s*"value": "\d*)\d