try this: > x <- c('WORD(12 )', 'WORD[123)', 'WORD ( 123 )', "WORD(xx)", "WORD(1)") > grep("[[:alnum:]]+[[:space:]]*\\([[:space:]]*[[:digit:]]+[[:space:]]*\\)", x) [1] 1 3 5 >
On Fri, Nov 13, 2009 at 9:12 AM, Dennis Fisher <fis...@plessthan.com> wrote: > Colleagues, > > I am using R (2.9.2, all platforms) to search for a complicated text string > using regular expressions. I would appreciate any help you can provide. > The string consists of the following elements: > SOMEWORDWITHNOSPACES > any number of spaces and/or tabs > ( > any number of spaces and/or tabs > integer > any number of spaces and/or tabs > ) > > Examples include: > WORD ( 123 ) > WORD(1 ) > WORD\t ( 21\t) > WORD \t ( 1 \t ) > etc. > > I don't need to substitute anything, only to identify if such a string > exists. > Any help with regular expressions would be appreciated. > Thanks. > > Dennis > > > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-866-PLessThan (1-866-753-7784) > Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.