Available inall subroutines.
Replaces the first occurrence of
pattern (a Perl-compatible regular expression) in
replacement. If no match is found, no replacement is made. Calls to
regsub do not set
This function may fail to make a replacement if the regular expression recurses too heavily. Such a situation may occur with lookahead and lookbehind assertions, or other recursing non-regular expressions. In this case,
fastly.error is set to
The following example deletes the query string portion of the request URL (equivalent to
set req.url = regsub(req.url, "\?.*$", "");
regsub is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.
Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.
Convert timestamps to relative times like '2 hours ago'
Search and replace in strings
Use regular expression substitution functions to map paths, strip extraneous slashes, and more.