This function compiles a regular expression from the second argument and searches for a regular expression match in the string supplied as the first argument. The return value is a string array containing the matched strings. This first index is the string which the entire regular expression matched, each index after the first represents any captured text using the capturing groups syntax: (). If no match occurs, an empty vector is returned.
The third argument is the offset into the input string to start the regular expression search.
In common with the other Regular Expression functions, this function is case insensitive by default. Also by default, the dot metacharacter character '.' does not match new line characters. You can change these behaviors using two options passed as the fourth argument.
The regular expression functions in SIMetrix/SIMPLIS support Perl-compatible regular expressions. Forward references, back references, alternation, capturing up to 99 groups, negative and positive look behind and ahead assertions are all supported. Regular expressions can be tested for validity with the RegExIsValid function.
Number | Type | Compulsory | Default | Description |
1 | string | Yes | String to search | |
2 | string | Yes | Regular expression | |
3 | real | No | 0 | Character offset |
4 | string | No | Options |
The input string to find the index where the regular expression match occurs.
The regular expression string.
The character position to start the regular expression search. 0 starts the search at the beginning of the input string.
Two options are supported :
Passing the first option 'casesensitive' makes the regular expression match case sensitive.The second option 'dotmatchesall' causes the dot('.') metacharacter to match new lines in the input string. You can pass both options as a string array:
[ 'casesensitive' , 'dotmatchesall' ]
Return type: string array
String array containing the matched strings.
RegExMatch('abcdef', 'de|bc' )returns the matched string, in this case 'bc'. A more advanced example where substrings are found and captured:
RegExMatch( 'POWER_SUPPLY_LOAD_3_RES' , '(SIMPLIS_DVM_ADVANCED|POWER_SUPPLY)_LOAD_(\d)' )returns a string array with three elements. The first element contains the entire matched text, the second element contains the string matched by the first captured group (SIMPLIS_DVM_ADVANCED|POWER_SUPPLY), the third element contains the text from the second captured group (\d):
'POWER_SUPPLY_LOAD_3' 'POWER_SUPPLY' '3'A failing match:
RegExMatch( 'res_z' , '(SIMPLIS_DVM_ADVANCED|POWER_SUPPLY)_LOAD_(\d)' )returns an empty vector. You can check the length of the return with the Length function.
▲Function Summary▲ | ||
◄ RegExIsValid | RegExp ▶ |