delimMatch(x, delims=c("{", "}"), syntax="Rd", escapeChar="\\", lineCommentChar="%")
x
giving the starting
position (in characters) of the first match, or -1 if there is
none, with attribute "match.length" giving the length (in
characters) of the matched text (or -1 for no match).
This function correctly handles nested delimiters.
The return value of this function has the same format as the value of the function
regexpr
.
This function was added for compatibility with R. In R,
the function
delimMatch
is located in the
"tools" package. The S-PLUS version of this function differs from the
R version in several ways:
- the delimiter characters can be more than one character long. For example,
delim=c("/*", "*/")
is valid in S-PLUS.
- the
syntax
argument is ignored in S-PLUS.
- the S-PLUS version of the function has these additional arguments:
escapeChar
and
lineCommentChar
. Their default values are the same as those used for the escape character
and the line comment character in R.
x <- c("value{foo}", "function(bar)", "% ignore these {foo} and (bar)", "foo1(foo2(x) + foo3(y))") r <-delimMatch(x) substring(x, r, r + attr(r, "match.length") - 1) # returns: "{foo}" "" "" "" r <-delimMatch(x, c("(", ")")) substring(x, r, r + attr(r, "match.length") - 1) # returns: "" "(bar)" "" "(foo2(x) + foo3(y))" # Search for C style comments, ignoring C++ style comment lines x <- readLines(file.path(getenv("SHOME"), "include", "S.h")) r <- delimMatch(x, delim = c("/*", "*/"), lineCommentChar = "//") y <- substring(x, r, r + attr(r, "match.length") - 1) y[nchar(y) > 0]