0

I'm trying to construct a VS22 Find Replace regex expression which will match a specific series of groups on lines of code, and use another expression to update those matching groups.

The lines of code are something like this:

[HttpGet, Route("api/v1/blob"), MyFilter(Keep = "res.Axe, res.Drop")]
[HttpGet, Route("api/v1/blob/{id}/track/{adid}"), MyFilter(Keep = "res.Axe, res.Edit, res.Drop")]
[HttpPut, Route("api/v1/blob/{id}/track/{adid}"), MyFilter(Keep = "res.Axe, res.Edit, res.Build")]

I want to:

  • remove the Keep = replace all of the , in the string literals
  • within the MyFilter(Keep = ...) instances

So I've built the best regex expression I can with groups to target the strings which are surrounded by " or ,, but preceded by Keep = ...

.*Keep =.*(?<=[",]).*\..*(?=[,"])

However, this appears to be matching the entire row and when I use this replace expression:

"$1 $2"

it replaces each matching row with this:

"$1 $2"")]

How can I modify these expressions to effectively split the string literals found in the MyFilter(Keep = ...) expressions into a list of strings, going from this example:

MyFilter(Keep = "res.Axe, res.Drop")

to this:

MyFilter("res.Axe", "res.Drop")
Matt W
  • 11,753
  • 25
  • 118
  • 215
  • Perhaps you can do it in 2 steps, first match `(?<=MyFilter\(Keep\s+=\s+""[^""]*),\s*` see https://regex101.com/r/iHEHrN/1 And then replace with `", "` and then match `(MyFilter\()Keep = "` and replace with `$1"` See https://regex101.com/r/sZYxsI/1 – The fourth bird Feb 02 '23 at 22:46

0 Answers0