Explanation: anything enclosed within a pair of forward slashes / signals that it is a regex. As such, we need to use the backslash to escape the forward slash to get \/. The g at the end is a flag to perform a global search, and thus replaces all occurrence of / with :.
Experienced web developer with 9 years of expertise in Accessibility, Analytics, UI, and Responsiveness. Currently focused on React. Rock climber and hot sauce maker.
If you still need the regex way of doing this:
Explanation: anything enclosed within a pair of forward slashes
/
signals that it is a regex. As such, we need to use the backslash to escape the forward slash to get\/
. Theg
at the end is a flag to perform a global search, and thus replaces all occurrence of/
with:
.Nicely put :)
Thank you
One and done function is better than two! Use this all the time.
I saw this exact method used to solve a problem on GitHub but I could not understand the use of forward slash and g. Thanks for this!