Name
PatternFindStrDirect -- parse a string using pattern matching (V6.0)
Synopsis
start, end, ... = PatternFindStrDirect(s$, pat$[, start, encoding])
Function
This function parses the string specified in s$ according to the pattern specified in pat$. If there is a match, the indices of where the match starts and ends in the source string are returned together with all strings that have been captured. If there is no match, PatternFindStrDirect() will return -1. The optional argument start can be used to specify a character index inside s$ where searching should begin. This defaults to 0 which means PatternFindStrDirect() should start at the beginning of s$.

This function does pretty much the same as PatternFindStr() but does not require you to use a generic For statement. Instead, all captures are returned along with the start and end indices. Keep in mind, though, that PatternFindStrDirect() does not operate inside a generic For loop, so only the first occurrence of pat$ inside s$ will be handled of course.

If you do not need the start and end indices, you can also use the PatternFindStrShort() function instead. See PatternFindStrShort for details.

The pattern specified in pat$ must adhere to the pattern syntax as described in the documentation of the PatternReplaceStr() function. See PatternReplaceStr for details.

The optional encoding parameter can be used to set the character encoding to use. This defaults to the default string encoding set using SetDefaultEncoding(). See Character encodings for details.

Inputs
s$
string to parse
pat$
pattern according to which the string should be parsed
start
optional: position where search should start (defaults to 0)
encoding
optional: character encoding to use (defaults to default string encoding) (V7.0)
Results
start
position of the first match inside s$ or -1 for no match
end
position of the last match inside s$
...
individual strings with all captures
Example
DebugPrint(PatternFindStrDirect("Name=Andreas", "(%w+)=(%w+)"))
The above example returns the strings next to the equal sign and the range 0 to 11 which describes the complete source string.

Show TOC