Use "^" to match the beginning of a string. I'm not sure how the "()" is
interpretted.
S> regexpr("^JA?[0-9]+","JA87")
[1] 1
attr(, "match.length"):
[1] 4
S> regexpr("^JA?[0-9]+","JB87")
[1] -1
attr(, "match.length"):
[1] -1
R> regexpr("^JA?[0-9]+","JA87")
[1] 1
attr(,"match.length")
[1] 4
R> regexpr("^JA?[0-9]+","JB87")
[1] -1
attr(,"match.length")
[1] -1
array chip wrote:
Hi,
I encountered a problem using "regexpr". The code
works fine in R, but not in S-Plus:
when run in R, it shows what I wanted (and it make
sense as well):
regexpr("(JA)?[0-9]+","JA87")
[1] 1
attr(,"match.length")
[1] 4
but if I try it in S-Plus:
regexpr("(JA)?[0-9]+","JA87")
[1] -1
attr(, "match.length"):
[1] -1
Basically, I wanted to match a pattern where there
might be letters "JA" preceding some numbers. Is there
something wrong with my code, or this a bug is S-Plus?
Thanks
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|