regsuball

STRINGregsuballSTRINGinputSTRINGpatternSTRINGreplacement

Available in all 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.

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 solution recipes, which show real world use cases. Click RUN 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 (regsub) to map paths, strip extraneous slashes, and more.

Compute intersection of two lists

Useful for comparing capabilities with required permissions.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.