DEV Community

miku86
miku86

Posted on • Edited on

Diary - 2018.08.24

I know the Basics of Regex, today I learnt something new:

When copying code, I always had the urge to change from this:

.then(function(response) {

to this:

.then((response) => {

So today, I just built a solution.

To get this result, using Visual Studio Code,
hit CMD + H, then Alt + R,
to open the Replace Window and include Regex.

First Box: function\((.*)\)\s*{
Second Box: ($1) => {

Explanation:

function => the word "function"
\( => escaped (
( => open capturing group
.* => zero or more times any single character => captured group
) => close capturing group
\) => escaped )
\s* => zero or more times whitespace
{ => {
Enter fullscreen mode Exit fullscreen mode
($1) => use the the captured group
=> { => => {
Enter fullscreen mode Exit fullscreen mode

Top comments (0)