regsuball

STRINGregsuballSTRINGinputSTRINGpatternSTRINGreplacement

Available inall subroutines.

Replaces all occurrences of pattern, which may be a Perl-compatible regular expression, in input with replacement. If no matches are found, no replacements are made.

Once a replacement is made, substitutions continue from the end of the replaced buffer. Therefore, regsuball("aaa", "a", "aa") will return a string "aaaaaa" instead of recursing indefinitely.

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 EREGRECUR.

Groups captured with pattern can be used in the replacement string. Read the regsub documentation for more information.

This function is not prefixed with the std. namespace.

Errors

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 EREGRECUR.

Example

set req.url = regsuball(req.url, "\+", "%2520");

Try it out

regsuball 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.

Search and replace in strings

Use regular expression substitution functions to map paths, strip extraneous slashes, and more.

Compute intersection of two lists

Useful for comparing capabilities with required permissions.

User contributed notes

BETA

Do you see an error in this page? Do you have an interesting use case, example or edge case people should know about? Share your knowledge and help people who are reading this page! (Comments are moderated; for support, please contact Fastly support)