Changing regex delimiters
Typically, when performing a substitution, you would use the
:s command followed by a regular expression that’s delimited by slashes
/ and followed by any flags, such as
g to replace all occurrences on the line. For example:
But did you know that the regular expression delimiter can be anything and is not limited to
/? This command is equivalent:
Whatever character you use after the
s is considered the delimiter. You can use almost any character except
|. Why would you care to use a different delimiter? Because then you don’t need to escape the slash.. For example, replacing a file path: Instead of:
You can use
# as your delimiter and skip escaping the
/ which makes for something far easier to parse:
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?