[R] a grep/regexpr problem

Rajarshi Guha rxg218 at psu.edu
Fri Feb 6 19:49:30 CET 2004


Hi,
  I'm trying to parse lines of the form:

dan001.hin (0): fingerprint={256, 411, 426, 947, 973, 976}

What I need is the sequence of number between {}. I'm using grep as

match <- grep("{([0-9,\s]*)}",s,perl=T,value=T)

where s is a character vector.

But all I get is the whole string s. I tried using regexpr in an attempt
to get just the sequence I wanted:

match <- regexpr("{([0-9,\s]*)}", s , perl=T) 

but then I get -1 as the return value indicating that there was no
match. 

If grep is able to return the matched element (though I dont know why
the whole string is being returned) why is regexpr failing?

Finally, could anybody provide a hint as to how I should modify the
regex to get the sequence between {}. (I've used the same regex in
Python code to get the sequence and it works fine.)

Thanks,


-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Entropy requires no maintenance.
-- Markoff Chaney




More information about the R-help mailing list