查找代码库中的所有单词列表中的单词实例。

huangapple go评论68阅读模式
英文:

Find all instances of word from a list of words across my entire codebase

问题

我想知道是否可以通过搜索整个代码库来查找我传递的关键字数组的实例。

目前我在vscode中使用搜索功能,但这只允许一次搜索一个单词,而我有数百个关键字。

我愿意使用任何可用的工具,比如vscode扩展、npm包,或者我自己能编写的东西,只要能加速这个过程。

我想要搜索的代码库是基于React的。

英文:

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.

答案1

得分: 1

可以使用正则表达式(在VSCode搜索菜单中原生可用)。

然后,您可以将查询编写为正则表达式,例如像这样:

word1|word2|word3

您可以使用一个快速算法将数组转换为这种形式,这样您只需复制粘贴结果:

array.join('|')
英文:

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

查找代码库中的所有单词列表中的单词实例。

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('|')

答案2

得分: 1

我建议使用正则表达式。在VS Code项目搜索中执行以下操作:

关键词1|关键词2|关键词3

并确保已启用正则表达式模式:

查找代码库中的所有单词列表中的单词实例。

英文:

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:

查找代码库中的所有单词列表中的单词实例。

答案3

得分: 1

你可以在VSCode中使用正则表达式搜索来查找一系列搜索词。

示例:

(wordOne|wordTwo)

为了仅匹配该单词而不匹配部分单词(例如,单词 data 仅匹配 data 而不匹配 newData 等),请添加正则表达式的单词边界:

\b(wordOne|wordTwo)\b

记得在搜索中启用正则表达式匹配!

英文:

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!

huangapple
  • 本文由 发表于 2023年7月17日 21:19:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定