-1

I have the following expression:

Category = context.Categories.First(x => x.Name == "API")

I need to match all lines with this format but instead of API it can be anything, e.g., between "" it can have anything.

I tried (https://regex101.com/r/PUuxjZ/1):

(?<=Category = context.Categories.First(x => x.Name == ")(.*)(?="))

Somehow this does not match the previous string. What am I missing?

merlin2011
  • 63,368
  • 37
  • 161
  • 279
Miguel Moura
  • 28,129
  • 59
  • 187
  • 356
  • In what language / environment? – revo Dec 28 '16 at 19:50
  • This is to use in a Find / Replace in Visual Studio Code. I suppose it uses C#? Not sure ... – Miguel Moura Dec 28 '16 at 19:51
  • What do you mean "it can be anything"? Are you trying to check if Category.Name has a value? – Matthew Meppiel Dec 28 '16 at 19:51
  • `\QCategory = context.Categories.First(x => x.Name == \E".*?"\)` Also I think you'd like to check this [*Reference - What does this regex mean?*](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – revo Dec 28 '16 at 19:52
  • @MatthewMeppiel No, I just have around 3000 code lines which include that text and in each the "..." part is different. I need to replace all them by something else. – Miguel Moura Dec 28 '16 at 19:53

1 Answers1

2

No need to use lookahead and lookbehind. Just search.

(Category = context.Categories.First\(x => x.Name == ").*("\))

If you want to replace, simplify the process by replacing with the content you already matched.

$1SomeOtherString$2

Perhaps not complicated, but it works.

Jeremy Fortune
  • 2,169
  • 1
  • 14
  • 16