Reputation: 5192
For example I have a file with multiple lines, some of the lines have a string "SocialInsuranceNumber": "123456789",
while some may have SocialInsuranceNumber": null,
. I need to find all such lines by using regular expression. And eventually replace the value after :
.
Any suggestion how to write a regex in this case?
Upvotes: 0
Views: 47
Reputation: 627488
You may use
"SocialInsuranceNumber"\s*:\s*(?:"\d+"|null),
See the regex demo.
The pattern matches:
"SocialInsuranceNumber"
- a literal char sequence\s*:\s*
- a hyphen enclosed with 0+ whitespaces (\s*
)(?:"\d+"|null)
- a non-capturing with two alternatives:
"\d+"
- "
, 1+ digits, "
|
- ornull
- a sequence of literal chars,
- a literal comma Upvotes: 1