ph_regexdiff PowerHome formula function
Description
searches a string of data and returns the data between two regular expression searches.
Syntax
ph_regexdiff ( pat1, pat2, data, start, flags )
Argument Description
pat1 String. The starting regular expression search pattern.
pat2 String. The ending regular expression search pattern.
data String. The string in which to perform the search.
start Long. The position within the data in which to start the search. Use 1 to start at the beginning.
flags Integer. Flags that control how the search is performed. Add individual flag values together. Add 1 to cause the search to match case. Add 2 to cause the search to ignore cr/lf's within the data.
Return value
String. Returns the data string between the pat1 regular expression and pat2 regular expression.
Usage
Use this function for powerful text search capabilities. The regular expression special characters supported are:
. Matches any character.
\< This matches the start of a word, where a word is defined in the traditional sense, that is, letters, or number. Spaces, punctuation, CR/LF, etc. would not be included as part of a word, and thus create a break.
\> This matches the end of a word. See also word definition above.
\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 the special characters is that they can conduct 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.

NOTE: If a string contains any quote characters (") then the string must be delimited with the single quote charcter ('). For example... 'he said, "no"'

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.

Within each search pattern you may perform multiple searches by separating your search pattern using the PowerHome escape character ~255. This is most useful when CF/LF IS NOT replaced and trying to match a particular piece of data that spans multiple lines. If you do multiple searches, the last search is used as the starting position and ending position of the returned text.

This function is often used with other PH string functions to trim a larger string, or to locate a string position within another string. See also pos(), posw(), ph_pos(), left(), mid(), right().

See also the .FAQs-String Tips-Hints Help file.

Examples
The following examples demonstrate typical syntax/usage for this function.
The following examples assume that the following string (with CR/LF line enders) is stored in [LOCAL1]...
  ROMId,Name, Value,Avg,
"3F000001CD92C728","Refrig",39.20,37.46,
"3F6000017C8BD128","Outside",23.90,19.81,
"3F000001CDB2BA27","House",70.65,70.13,
"3F000001CD9E6D28","Freezer",1.96,1.11,

The following command uses a CR/LF Flag of "0" to search only lines ...
ph_regexdiff ("ROMId,", ", Val", "[LOCAL1]", 1, 0 ) --> Finds Name

While this expression with the CR/LF Flag set to search thru everything (2) ...
ph_regexdiff ("ROMId,", ", Val", "[LOCAL1]", 1, 2 ) --> Finds all characters from "Name" to the ending comma after 1.11 (ie, Name ... 1.11,)

This ...
ph_regexdiff ('3F.+",', ',', '[LOCAL1]', 1,0 ) --> Finds 39.20

While ...
ph_regexdiff ('3F.+",', ',', '[LOCAL1]', 1,2 ) --> finds 1.96

====

More Examples: {Searching in LOCAL1}
  ph_regexdiff ('2C728', '\<', '[LOCAL1]', 1,0 ) --> finds "," (Between ..C728 and Refrig..)
ph_regexdiff ('2C728', '\>', '[LOCAL1]', 1,0 ) --> finds ","Refrig
ph_regexdiff ('BA27...', "7", '[LOCAL1]', 1,0 ) --> finds House",
ph_regexdiff ('Refrig', "$", '[LOCAL1]', 1,0 ) --> finds ",39.20,37.46,
ph_regexdiff ("3F[0-9]+","R", "[LOCAL1]", 1,0 ) --> finds CD92C728","