FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
ReplaceStrRegex
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
ReplaceStrRegex( value, pattern, replace, [ first_only ] )
replace_str_regex( value, pattern, replace, [ first_only ] )
ReplaceStrRegex( value, pattern, replace, [ first_only ] )
ReplaceStrRegex( value, pattern, replace, [ first_only ] )
ReplaceStrRegex( value, pattern, replace, [ first_only ] )
ReplaceStrRegex( value, pattern, replace, [ first_only ] )
Description
The ReplaceStrRegex
function returns a string which has either the first or
all occurrences of the pattern
replaced with the replace
string. The
pattern conforms to Java regular expression syntax.
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
String |
The source String to perform replacements within. |
|
String |
The Java regular expression to match against the |
|
String |
The new String that replaces the sub-string found by |
|
Boolean |
Optional - When Since Go does not have function overloading or optional arguments, you
must use the function |
Returns
A String which has either the first or all occurrences of the
pattern
replaced with the replace
string.
Examples
The following query executes an array of independent ReplaceStrRegex
operations and returns the results in an Array. The result array
position matches the execution array position.
The individual operations are:
-
The string "One Fish Two Fish" is processed, replacing the pattern "Two" with the string "Blue". The result string "One Fish Blue Fish" is placed in the top position of the result array.
-
The string "One Fisk Two FisT" is processed, replacing every string matching the pattern "Fis." with the string "Fish". The result string "One Fish Two Fish" is placed in the second position of the result array.
-
The same string "One Fisk Two FisT" is processed, but because it has the
first_only
flag set totrue
, only the first string matching the pattern "Fis." is replaced. The result string "One Fish Two FisT" is placed in the third position of the result array.
[ 'One Fish Blue Fish', 'One Fish Two Fish', 'One Fish Two FisT' ]
["One Fish Blue Fish", "One Fish Two Fish", "One Fish Two FisT"]
[One Fish Blue Fish One Fish Two Fish One Fish Two FisT]
Arr(StringV(One Fish Blue Fish), StringV(One Fish Two Fish), StringV(One Fish Two FisT))
["One Fish Blue Fish", "One Fish Two Fish", "One Fish Two FisT"]
[ 'One Fish Blue Fish', 'One Fish Two Fish', 'One Fish Two FisT' ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!