[R] grep searching for sequence of 3 consecutive upper case letters

2006-11-06 Thread Lapointe, Pierre
Hello,

I need to identify all elements which have a sequence of 3 consecutive upper
case letters, anywhere in the string.

I tested my grep expression on this site: http://regexlib.com/RETester.aspx

But when I try it in R, it does not filter anything.

str -c(AGH, this WOUld be good, Not Good at All)
str[grep('[A-Z]{3}',str)] #looking for a sequence of 3 consecutive upper
case letters

[1] AGHthis WOUld be good Not Good at All   

Any idea?

Pierre

**
AVIS DE NON-RESPONSABILITE: Ce document transmis par courrie...{{dropped}}

__
R-help@stat.math.ethz.ch 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.


Re: [R] grep searching for sequence of 3 consecutive upper case letters

2006-11-06 Thread David Barron
Try

str[grep('[[:upper:]]{3}',str)]


On 06/11/06, Lapointe, Pierre [EMAIL PROTECTED] wrote:
 Hello,

 I need to identify all elements which have a sequence of 3 consecutive upper
 case letters, anywhere in the string.

 I tested my grep expression on this site: http://regexlib.com/RETester.aspx

 But when I try it in R, it does not filter anything.

 str -c(AGH, this WOUld be good, Not Good at All)
 str[grep('[A-Z]{3}',str)] #looking for a sequence of 3 consecutive upper
 case letters

 [1] AGHthis WOUld be good Not Good at All

 Any idea?

 Pierre

 **
 AVIS DE NON-RESPONSABILITE: Ce document transmis par courrie...{{dropped}}

 __
 R-help@stat.math.ethz.ch 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.



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

__
R-help@stat.math.ethz.ch 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.


Re: [R] grep searching for sequence of 3 consecutive upper case letters

2006-11-06 Thread rfrancois
Quoting David Barron [EMAIL PROTECTED]:

 Try

 str[grep('[[:upper:]]{3}',str)]


or more efficiently :

grep('[[:upper:]]{3}', str, value = TRUE)


 On 06/11/06, Lapointe, Pierre [EMAIL PROTECTED] wrote:
 Hello,

 I need to identify all elements which have a sequence of 3 consecutive upper
 case letters, anywhere in the string.

 I tested my grep expression on this site: http://regexlib.com/RETester.aspx

 But when I try it in R, it does not filter anything.

 str -c(AGH, this WOUld be good, Not Good at All)
 str[grep('[A-Z]{3}',str)] #looking for a sequence of 3 consecutive upper
 case letters

 [1] AGHthis WOUld be good Not Good at All

 Any idea?

 Pierre

 **
 AVIS DE NON-RESPONSABILITE: Ce document transmis par courrie...{{dropped}}

 __
 R-help@stat.math.ethz.ch 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.



 --
 =
 David Barron
 Said Business School
 University of Oxford
 Park End Street
 Oxford OX1 1HP

 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.


Re: [R] grep searching for sequence of 3 consecutive upper case letters

2006-11-06 Thread Peter Dalgaard
Lapointe, Pierre [EMAIL PROTECTED] writes:

 Hello,
 
 I need to identify all elements which have a sequence of 3 consecutive upper
 case letters, anywhere in the string.
 
 I tested my grep expression on this site: http://regexlib.com/RETester.aspx
 
 But when I try it in R, it does not filter anything.
 
 str -c(AGH, this WOUld be good, Not Good at All)
 str[grep('[A-Z]{3}',str)] #looking for a sequence of 3 consecutive upper
 case letters
 
 [1] AGHthis WOUld be good Not Good at All   
 
 Any idea?

There are multiple versions of RE's, and fine details resolve in
different ways. Don't expect the RETester to hold the Final Truth; it
seems to relate to a particular programming environment, which is not
R.  

 grep('[A-Z]{3}', str, perl=TRUE)
[1] 1 2

Not only that, but

 grep('[ABCDEFGHIJKLMNOPQRSTUVWXYZ]{3}', str)
[1] 1 2

Hint: What is your collating sequence?

 Sys.setlocale(LC_COLLATE, C)
[1] C
 grep('[A-Z]{3}', str)
[1] 1 2


-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch 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.