ReplaceStrRegex

Not available in this language yet.
ReplaceStrRegex( value, pattern, replace, [ first ] )
ReplaceStrRegex( value, pattern, replace, [ first ] )
ReplaceStrRegex( value, pattern, replace, [ first ] )
Not available in this language yet.
ReplaceStrRegex( value, pattern, replace, [ first ] )

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

Argument Type Definition and Requirements

value

String

The source string to search through.

pattern

String

The Java regular expression to be found in the source string.

replace

String

The new string that replaces the find string.

first_only

Boolean

Optional - Replace only the first occurrence of the pattern. Default is false.

Returns

A string value which has either the first or all occurrences of the pattern replaced with the replace string.

Examples

The query below executes an array of independent ReplaceStrRegex operations and returns the results in an array. The result array position matches the execution array position. The first operation takes the string "One Fish Two Fish" and replaces the pattern "Two" with the string "Blue". The resultant string "One Fish Blue Fish" is placed in the top position of the result array. The second operation takes the string "One Fisk Two FisT" and replaces every string matching the pattern "Fis." with the string "Fish". The new string "One Fish Two Fish" is placed in the second position of the result array. The third operation takes the same string "One Fisk Two FisT", but because it has the first_only flag set to true, only replaces the first string matching the pattern "Fis." The new string "One Fish Two FisT" is placed in the third position of the result array.

Not available in this language yet.
Not available in this language yet.
System.out.println(
  client.query(
    Arr(
       ReplaceStrRegex("One Fish Two Fish", "Two", "Blue"),
       ReplaceStrRegex("One Fisk Two FisT", "Fis.", "Fish"),
       ReplaceStrRegex("One Fisk Two FisT", "Fis.", "Fish", true)
    )
  ).get());
[
   "One Fish Blue Fish", 
   "One Fish Two Fish", 
   "One Fish Two FisT"
]
Not available in this language yet.
Not available in this language yet.
Not available in this language yet.

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!