ph_replaceallregex3 PowerHome formula function
Description
Uses C# regular expressions to replace ALL occurences of matches within a string of data  
Syntax
ph_replaceallregex3 ( as_pattern, as_replace, as_data, ai_flags )
Argument Description
as_pattern String. The regular expression pattern to match which may include capturing groups
as_replace String. The replace (substitution) pattern to apply to matches from as_pattern
as_data String. The string of data on which to perform the regular expression operations
ai_flags Integer. A flags parameter that controls how the regular expression is processed. See Usage below for details
Return value
String. Returns the as_data parameter with matches appropriately substituted based upon the replace pattern 
Usage
Use this function to search and replace data within a supplied string using C# regular expression operations as the basis of the search and replacement. See this link for an explanation on regular expression substitutions: https://docs.microsoft.com/en-us/dotnet/standard/base-types/substitutions-in-regular-expressions

The ai_flags parameter controls how the regular expression search is done. The value for each desired option below would be added together to arrive at the proper ai_flags value. If none of the additional options are required, then use an ai_flags value of 0. For a detailed explanation of eachof the options, see this link: https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=netcore-3.1

  • 1 - Ignore Case
  • 2 - Multiline
  • 4 - Explicit Capture
  • 8 - Compiled
  • 16 - Single Line
  • 32 - Ignore Pattern Whitespace
  • 64 - Right to Left
  • 256 - ECMA Script
  • 512 - Culture Invariant
  • Examples
    The following examples demonstrate typical syntax/usage for this function.
    • ph_replaceallregex3("[^a-f]*([a-f]+)[^a-f]*","$1","This is a bc test def",0) - Returns "abcedef". This example searches for any characters that are not "a" thru "f" and matches those. When any character that matches "a" thru "f" is encountered, it is then identified in the capturing group that is surrounded by "(" and ")" characters. This is capture group 1. This is followed by matching any characters that are not "a" thru "f". In regular expression processing, "This is " is matched by the section of the regular expression that is any character that is not "a" thru "f". The next character "a" is matched by the capturing group. The space character following the "a" is matched by the section following the capturing group that is match any character that is not "a" thru "f". The "bc" following this space does not match so the entire matched string is now replaced according to the as_replace pattern "$1" which says to replace the entire matched section, which in this case is "This is a ", with capture 1, which is "a". This process repeats itself until all of as_data has been matched/replaced. 
    • ph_replaceallregex3("[a-f]+","*","This is a bc test def",0) - Returns "This is * * t*st *". This example does not specify a capturing group in the as_pattern regular expression and instead only matches on one or more characters that match "a" thru "f". Whenever a match is encountered, it is replaced by an asterisk "*" character. Non matching characters are ignored which means they will NOT be replaced and will instead be part of the returned string.