If you’re using Atom as your text editor, it’s easy to do this using Regex.
- First pull up the find in buffer bar, by going to Find > Find in Buffer.
- In the first search field titled Find in current buffer type in console.log.*$
- Select the Use Regex option found in the upper right corner of the search panel that’s designated by the icon .*
- Press Find All to find all instances of
console.log()and then press Replace All
In step 2, we used a regex to grab all instances of the string
console.log till the end of the line. By using
. indicates we want to match any character,
* is used to indicate we want to match in indefinite amount of any characters and then finally
$ is used to indicate to match until the end of the line.
If you’re wondering why we left the second field of the Find in Buffer panel it’s because we don’t want to replace all the
console.log()s with anything. By leaving it blank it is saying replace with nothing.
Wrapping up, the regex to remove is the following: