Search smart in VSCode using regex

Search smart in VSCode using regex

I was in the middle of writing a unit test case for some service built-in JavaScript using Jest. We need to mock data instead of actually having a connection using a database instance. In particular model response json data, I need to search for a particular format and replace it with mock data, like below:

So I have used the regex option in the VSCode search feature like below:

  1. Cmd+F to show the search bar

  2. Select regex option

  3. Type :\s\b(curr.\w+)\b, in search input and type : "mock", in replace input box

Explanation for the above regex:

  1. \s empty one space

  2. \b word boundary starts and ends

  3. \w any length word

  4. + plus a quantifier that matches one or more occurrences of the preceding element.

Have a happy regex search.
Thanks for reading!