extract: Extract a Parenthetically-grouped Substring of a Regular...

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Given a regular expression with parenthetically-grouped substrings, return or drop the substring of interest.

Usage

1
extract(x, pattern, group = 0, invert = FALSE, ...)

Arguments

x

character

pattern

passed to regexec

group

one less than the index used by regexec

invert

drop the matched text, returning everything else

...

ignored

Details

regexec determines all the numbered matches corresponding to sets of parentheses. extract uses these to locate and return particular numbered matches, or to delete them, returning what remains. group = 0 refers to the entire match (first element of each regexec result). Non-matches give an empty string; matching NA results in NA.

Value

character

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

1
2
3
x <- c(' kg ',' //a/A//b/B// ',NA,' kg [ 4 , 8.2 ]','(,1.025e-6]','(,] ')
pattern <- '((\\(|\\[) *([-+eE.0-9]*) *, *([-+eE.0-9]*) *(\\)|\\])) *$'
extract(x,pattern,group=5)	

metrumrg documentation built on May 2, 2019, 5:55 p.m.