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