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:
Cmd+F to show the search bar
Select regex option
Type
:\s\b(curr.\w+)\b,
in search input and type: "mock",
in replace input box
Explanation for the above regex:
\s empty one space
\b word boundary starts and ends
\w any length word
+
plus a quantifier that matches one or more occurrences of the preceding element.
Have a happy regex search.
Thanks for reading!