Performs a regular expression search and replace on all occurences within a string of data.
String. Returns the data string with the appropriate replacements performed.
Use this function for powerful text search and replace capabilities. The regular expression special characters supported are:
. |
Matches any character. |
\( |
This marks the start of a region for tagging a match. |
\) |
This marks the end of a tagged region. |
\n |
Where n is 1 through 9 refers to the first through ninth tagged region when replacing. For example, if the search string was Fred\([1-9]\)XXX and the replace string was Sam\1YYY, when applied to Fred2XXX this would generate Sam2YYY. |
\< |
This matches the start of a word. |
\> |
This matches the end of a word. |
\x |
This allows you to use a character x that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set. |
[...] |
This indicates a set of characters, for example, [abc] means any of the characters a, b or c. You can also use ranges, for example [a-z] for any lower case character. |
[^...] |
The complement of the characters in the set. For example, [^A-Za-z] means any character except an alphabetic character. |
^ |
This matches the start of a line (unless used inside a set, see above). |
$ |
This matches the end of a line. |
* |
This matches 0 or more times. For example, Sa*m matches Sm, Sam, Saam, Saaam and so on. |
+ |
This matches 1 or more times. For example, Sa+m matches Sam, Saam, Saaam and so on. |
An important note on this function is that it is a "greedy" regular expression search. When using the * and + special characters this function will not stop at the first match but will instead go to the last match.
This function will also not perform a regular expression search that spans multiple lines. If the data to search contains carraige returns or line feeds, the entire matching search data for the regular expression must exist within a single line. If your regular expression must span across a line, then add 2 to the flags to have CR's and LF's temporarily converted. CR will be converted to ASCII 128 and LF will be converted to ASCII 129. If you convert CF/LF then you can include them in your search with PowerHome escape characters ~128 and ~129 respectively.
You may perform multiple search and replaces by separating your search and replace patterns with the PowerHome escape character ~255. If you have more searches than replaces then the last replace pattern will be used for the remaining searches.
You may also perform multiple searches within a single search pattern section by separating your searchs using the PowerHome escape character ~254. If you do multiple searches, then replacement will only be performed on the last search within a search pattern section.