Class Utility.RegEx

persistent class Utility.RegEx extends %Persistent, %XML.Adaptor

SQL Table Name:

Interface to the Perl Compatible Regular Expression library.

Class Parameters

• parameter DLLLocation
The location (including path) of the regular expression DLL/shared object. Setting this parameter is required for proper functioning of this class.

Properties

• binarystream property CompiledPattern As %Stream
The compiled version of the pattern specified in Pattern. When a RegEx object is saved and reloaded, it won't need to compile the regular expression again; this can increase performance if the same regular expression is used often.
• property Data As %String (MAXLEN = 32767)  [Transient;]
When matching, data will be stored here so GetResult can return the proper substring.
• property Description As %String (MAXLEN = 32767)
Description of the pattern, can be used when saving patterns.
• property ErrorMessage As %String  [Transient;]
Error message returned from a PCRE call.
• property ErrorNumber As %Integer  [Transient;]
Error number returned from a PCRE call.
• list property Matches As %String  [Transient;]
After calling Match, a list of matches is stored here. The matches contain a string consisting of the starting and ending offset of the match in the supplied data, separated by a comma. To get the actual matching string, GetResult can be used. The first match is the full string that is matched, subsequent entries contain substring matches (if any).
• property Name As %String
Name of the pattern, can be used when saving patterns.
• array property NamedMatches As %String  [Transient;]
If named substring matches are requested, this array will contain them. The index is the name of the substring, the value is an index in the Matches property.
• property Pattern As %String (MAXLEN = 32767)
The current regular expression. When setting this property, the pattern is automatically compiled. If an error occurs during compilation, the PatternValid, ErrorNumber and ErrorMessage properties are set accordingly.
• property PatternValid As %Boolean  [InitialExpression = 0; Transient;]
Indicates whether the current regular expression in Pattern is a valid regular expression and compiled successfully.

Methods

• classmethod GetObjectByName(Name As %String) returns Utility.RegEx
Returns an instance of an already saved object for a given name.
• classmethod GetObjectByPattern(Pattern As %String, Create As %Boolean = 0, Name As %String = "", Description As %String = "") returns Utility.RegEx
Returns an instance of an already saved object for a given pattern. If no object with the specified pattern exists and Create is set, one will be created (with the specified name and description). For example,
 Set RegEx=##class(Utility.RegEx).GetObject("\w+",1,"Words")
 If '$IsObject(RegEx)  ;Handle error
 ;RegEx now contains a Utility.RegEx object with the specified pattern.
 ;The object is saved with name Words.
Note that the save may fail if another object, with a different pattern but the same name, is already present. The RegEx object will still be returned, but won't be saved.
• method GetResult(Index As %Integer) returns %String
Returns the string result for a given match index. Index is expected to contain an index into the Matches property; the returned result is the part of the data string this match represents.
• method Match(Data As %String, Offset As %Integer = 1) returns %Integer
Executes the pattern in Pattern aginst the supplied data; results are returned in Matches and NamedMatches. Returns 0 if no match was found, or 1 + the number of substring matches (if any) otherwise. If an error occurred during matching, the ErrorNumber and ErrorMessage properties are set. If Offset is specified, the search will start from that (1-based) offset in the supplied data.
• classmethod Matches(RegEx As %String, Value As %String) returns %Boolean
Simple stored procedure that can be used in queries. The first parameter is the pattern to use, the second the data to match with. The return value is 1 if the data matched, 0 otherwise. If the first character of the pattern is a colon (":"), the pattern is assumed to be a reference to a saved pattern. If the subsequent characters of Pattern are all numeric, they are taken to represent an object ID; otherwise, it is assumed they refer to a saved pattern's Name property.
• method NextMatch() returns %Integer
Retrieves the next match for the data specified in a previous call to Match. Updates the Matches and NamedMatches properties; returns 0 if no further match was found, or 1 + the number of substring matches (if any) otherwise. If an error occurred during matching, the ErrorNumber and ErrorMessage properties are set.
• classmethod Test(Pattern As %String, Data As %String, Offset As %Integer = 1) returns %Integer
Tests whether the supplied pattern matches the supplied data. Returns the offset in the supplied string of the first match, or 0 if no match was found or a pattern error occurred. If Offset is specified, the search will start from that (1-based) offset in the supplied data.

Indices

• index Name on Name  [Unique;]