VScode - regex find match in the middle and remove start and end

25 Views Asked by At

I want to replace all (start and end) of the string but the parameter in the middle (for example @ModelKey or @ProductNumber) from this Input

[MODEL_KEY] = IIF(@ModelKey IS NOT NULL, @ModelKey , [MODEL_KEY]), 
[PRODUCT_NUMBER] = IIF(@ProductNumber IS NOT NULL, @ProductNumber , [PRODUCT_NUMBER]), 

i need this output

@ModelKey
@ProductNumber

In my regex101.com example this works

(.*)(\@.*)(\sIS)(.*)

as expected

  1. Group $1 (.*) for example [MODEL_KEY] = IIF( can be removed
  2. Group $2 (\@.*) is the group to keep @ModelKey
  3. Group $3 and $4 (\sIS)(.*) are the groups that can be removed

As you can see in this image

Regex replace

But in vs code the expression (.*)(\@.*)(\sIS)(.*) results in an error message:

Invalid regular expression

Invalid esape

VS-code regex invalid

Question

0

There are 0 best solutions below