0
votes

I'd like to mask out sensitive credit card details. Therefore trying to create matcher that finds:

  • that there is a CreditCard tag
  • that the same line has a Number field
  • that the same line has a CVC field

<CreditCard Number="123456789" CVC="111" />

Then I want to replace the numbers/values that are found. So far I have: (CreditCard.*CVC=").*?". This would match the string CreditCard Number="123456789" CVC="111".

What do I have to change so that only the numbers inside either CVC or Number double quotes are matched?

1
Try XPath instead of Regex.Bergi
What language are you using? It would probably be a much better idea to use an XML parserExplosion Pills
Java, but the string where the XML is placed does not ONLY consist of xml, but lot's of other data. So I cannot use a parser...membersound
Are those attributes always in this order? Or could CVC occur before Number?Tim Pietzcker

1 Answers

2
votes

Lookahead and Lookbehind are the magic words. Here is an example to match your CVC number...

(?<=CVC=\")\d+(?=\")