Hi,

May be this helps:
str1<- "Brazil is the world's leading orange producer, with an output almost as 
high as that of the next three countries combined (the United States, India, 
and China). Orange groves are located mainly in the state of São Paulo, in the 
southeastern region of Brazil. Oranges, whose flavour may vary from sweet to 
sour, are commonly peeled and eaten fresh or squeezed for juice ora"

regmatches(str1,gregexpr("\\borange\\b",tolower(str1),perl=TRUE))[[1]]
#[1] "orange" "Orange"


 length(regmatches(str1,gregexpr("\\borange\\b",tolower(str1),perl=TRUE))[[1]])
#[1] 2
A.K.







----- Original Message -----
From: agrima srivastava <agrimasrivasta...@gmail.com>
To: r-help@r-project.org
Cc: 
Sent: Monday, September 30, 2013 1:45 AM
Subject: [R] str_count counts the substring

I am trying to count the number of times a word occurs in a string.
and using str_count function from the package stringr. This function counts
the substrings as well.
Is there a way in which I can exclude the substring count and just take the
exact match.
Thanks in advance.



-- 
Thanks and Regards
Agrima Srivastava
-------------------------------------------------------------------------------
Research Scholar
Computer Science & Information Systems Department
BITS Pilani Hyderabad Campus

    [[alternative HTML version deleted]]

______________________________________________
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.


______________________________________________
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.

Reply via email to