skip to Main Content

I’m wondering is it possible to search through my entire codebase to find instances of keywords I pass as an array.

Currently I’m using the search feature in vscode but this only allows one word at a time and I’ve got hundreds.

I’m happy to use whatever there is out there, vscode extension, npm package, something I’m able to code myself, just anything to speed this process up.

The codebase I’m wanting to search through is React based.

3

Answers


  1. For this you can use a regular expression (available natively in the search menu of vscode)

    Regex option

    Then you can write your query as a regex, for example like this

    word1|word2|word3
    

    You can use a quick algorithm to transform your array into this, so you can just copy paste the result

    array.join('|')
    
    Login or Signup to reply.
  2. I would recommend using regular expressions. Inside of the vscode project search do this:

    keyword1|keyword2|keyword3
    

    and make sure that you have regular expression mode turned on:

    enter image description here

    Login or Signup to reply.
  3. You can use regex search in VSCode to find a list of search terms.

    Example:

    (wordOne|wordTwo)
    

    Add regex word boundaries in order to match only that word without matching partial words (ie. the word data will match only data and not newData, for instance):

    b(wordOne|wordTwo)b
    

    Remember to turn on regex matching for the search!

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