skip to Main Content

I have several functions across different files, and they usually are like this:
"prefix":"functionName (...)", like pub:isInt. And I wanted to put the first letter of the function as capital, so I did this regex to change to pub:IsInt (this also rejects other non-intented matches, that is why it is like this):

MATCH: ([a-z]+):([a-z])([a-z t_:]*)?(?=()

REPLACE: $1:U$2$3

This works fine for one function, the problem is when I have several functions in the same line, like:

pv:collect(table | pv:hasElement(table) AND pv:element(table))

Search and Replace in multiple files does this:

pv:Collect(table | pv:Collect(table) AND pv:Collect(table))

which is wrong because $1, $2 and $3 match only the first for the whole line.

Search and Replace in one file does the correct:

pv:Collect(table | pv:HasElement(table) AND pv:Element(table))

Does anyone happen to know what the error might be?

2

Answers


  1. This looks like an actual bug in VSCode

    I’ve created an issue: https://github.com/microsoft/vscode/issues/196592

    enter image description here

    Login or Signup to reply.
  2. Your regex will match more than you think, see regex101 demo.

    VS Code will produce 2 matches as well IF you enable the MatchCase option – otherwise it’ll treat your [a-z] as [a-zA-Z].

    Perhaps you can use ^ at the beginning of the regex like:

    ^([a-z]+):([a-z])([a-zA-Z t_:]*)?(?=()    // need for the MatchCase option 
    

    You see I added A-Z so you don’t need the MatchCase option.

    I think what you really want is

    ([a-z]+):([a-z])([w t_:|()]*)(?=()
    

    I added |() to your character class. And I used w so it handles both lower and upper characters. See regex101 demo and tested in vscode.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search