RegExpr_FindPatternInText
- Updated2023-02-21
- 4 minute(s) read
int RegExpr_FindPatternInText (const char *regularExpressionText, int caseSensitive, const char *textToSearch, int textLength, int direction, int matchPolicy, int *matched, int *matchPosition, int *matchLength);
Purpose
This function searches a text buffer for a match to a regular expression.
See the Instrument help for example source code showing how to use this function.
Parameters
| Input | |||||||||||||||||||||||||||||||||||||||||
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||
| regularExpressionText | const char * | A nul–terminated string containing a regular expression. A regular expression consists of the following tokens:
|
|||||||||||||||||||||||||||||||||||||||
| caseSensitive | int | Specify a nonzero value or select Yes in the function panel to match characters on a case–sensitive basis. For example, "chr" matches only "chr" and not "CHR". Specify 0 or select No in the function panel to match characters on a case–insensitive basis. For example, "chr" matches "chr", "CHR", and "Chr". This parameter does apply to ranges. For example, if this parameter is non–zero, then "[a–z]" in the regular expression string matches any lowercase letter. If this parameter is zero, then "[a–z]" matches any letter. |
|||||||||||||||||||||||||||||||||||||||
| textToSearch | const char * | The text to match to the regular expression. The regular expression must match from the beginning of the text. If you want to search for a regular expression match anywhere in the text, you must call this function iteratively, each time passing the address of the next character in the text. See the Instrument Help for example source code. The function RegExpr_FindPatternInText performs this for you. |
|||||||||||||||||||||||||||||||||||||||
| textLength | int | The number of bytes in the text you want to be included to the search for a match to the regular expression. If you pass a value less than zero, the text is assumed to be nul–terminated, and the full length is used. |
|||||||||||||||||||||||||||||||||||||||
| direction | int | Specify a nonzero value or RegExpr_SearchForwards or select Forwards in the function panel to search the text starting at the beginning and working forwards. Specify 0 or RegExpr_SearchBackwardsor select Backwards in the function panel to search the text starting at the end and working backwards. |
|||||||||||||||||||||||||||||||||||||||
| matchPolicy | int | Specify a nonzero value or RegExpr_MatchLargestNumChars or select Match Largest Number of Chars in the function panel to match the maximum number of characters to the pattern. Specify 0 or RegExpr_MatchSmallestNumChars or select Match Smallest Number of Chars in the function panel to match the minimum number of characters to the pattern. Examples: If the pattern is "a+" and the text to search is "aaaaab", the match could be of length 1 or 5. If you specify RegExpr_MatchLargestNumChars, the match length will be 5. Otherwise, it will be 1. If the pattern is "a+b" and the text to search is "ababab", the match could be of length 2 or 6. If you specify RegExpr_MatchLargestNumChars, the match length will be 6. Otherwise, it will be 2. |
|||||||||||||||||||||||||||||||||||||||
| Output | |||||||||||||||||||||||||||||||||||||||||
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||
| matched | int | If there was a match, this parameter is set to 1. Otherwise, it is set to 0. | |||||||||||||||||||||||||||||||||||||||
| matchPosition | int | The zero–based index of the position within the text where the match to the regular expression begins. If there was no match, then the parameter is set to –1. |
|||||||||||||||||||||||||||||||||||||||
| matchLength | int | This parameter is set to the number of characters in the text that actually matched to the regular expression. The length does not include the terminating NUL byte. If there was no match, then the parameter is set to –1. |
|||||||||||||||||||||||||||||||||||||||
Return Value
| Name | Type | Description | ||||||||||||||||||||||||||||||
| parseStatus | int | Indicates if the regular expression was parsed successfully. If the string is not a valid regular expression, a negative error number is returned. You can pass this error number to the RegExpr_GetErrorString function. However, in some cases there is more error information than can be encoded in the error number. You can get more detailed information about the result of the last call to this function by calling RegExpr_GetErrorElaboration. The error numbers are:
|
Additional Information
Library: Regular Expressions
Include file: toolbox\regexpr.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later
Example
Refer to toolbox\RegEx.cws for an example of using the RegExpr_FindPatternInText function.