\w+ will match one or more word characters and \s* will match 0 or
more spacing characters so if this must the described text must be the
complete expression then:
grepl("^\\w+\\s*\\(\\s*\\w+\\s*\\)$", x)
or if its ok for other text to appear before and after as long as the
indicated text is amon
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 wrote:
> Colleagues,
>
> I am using R (2.9.2, all platforms) to s
On Nov 13, 2009, at 8:12 AM, Dennis Fisher 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
One of these should be a start. If there can be no extra text at the beginning or end, start with
"^" and end with "$".
x <- c("WORD ( 123)", "WORD(1 )", "WORD\t ( 21\t)", "WORD \t ( 1 \t )",
"decoy((2))", "more words in front(2)")
grep("[[:alpha:]]+[ \t]*\\([ \t]*[0-9]+[ \t]*\\)", x)
Hello,
The function you are looking for is grepl. Something like this perhaps:
> words <- c("WORD ( 123)","WORD(1)", "WORD\t ( 21\t) ", "WORD\t (
21\t) " )
> grepl( "[[:space:]]*[(][[:space:]]*[0-9]+[[:space:]]*[)]", words )
[1] TRUE TRUE TRUE TRUE
[[:space:]]* : any number of spaces
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
(
6 matches
Mail list logo