search for: regexpr

Displaying 20 results from an estimated 280 matches for "regexpr".

Did you mean: regexp
2008 Apr 15
1
why does regexpr not work with '.'
Dear R Helpers, I am running R 2.6.2 on a Windows XP machine. I am trying to use regexpr to locate full stops in strings, but, without success. Here an example:- f="a,b.c at d:" #define an arbitrary test string regexpr(',',f) #find the occurrences of ',' in f - should be one at location 2 # and this is what regexpr finds #[1] 2 #attr(,"ma...
2012 Aug 06
5
regexpr with accents
Hello, I have build a syntax to find out if a given substring is included in a larger string that works like this: d1$V1[regexpr("some text = 9",d1$V2)>0] <- 9 and this works all right till "some text" contains standard ASCII set. However, it does not work when accents are included as the following: d1$V1[regexpr("some t?xt = 9",d1$V2)>0] <- 9 I have tried to substitute "?&qu...
2003 Aug 13
7
Regexpr with "."
I'm trying to use the regexpr function to locate the decimal in a character string. Regardless of the position of the decimal, the function returns 1. For example, > regexpr(".", "Female.Alabama") [1] 1 attr(,"match.length") [1] 1 In trying to figure out what was going on here, I tried the be...
2010 Jun 01
1
regexpr help (match.length=0)
R-help, Sorry if this is more of a regex question than an R question. However, help would be appreciated on my use of the regexpr function. In the first example below, I ask for all characters (a-z) in 'abc123'; regexpr returns a 3-character match beginning at the first character. > regexpr("[[:alpha:]]*", "abc123") [1] 1 attr(,"match.length") [1] 3 However, when the text is flippe...
2004 Feb 06
3
a grep/regexpr problem
...e 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...
2007 Jun 29
2
regexpr
Hi, I 'd like to match each member of a list to a target string, e.g. ------------------------------ mylist=c("MN","NY","FL") g=regexpr(mylist[1], "Those from MN:") if (g>0) { "On list" } ------------------------------ My question is: How to add an end-of-string symbol '$' to the to-match string? so that 'M' won't match. Of course, "MN$" will work, but i want to use it in a loo...
2010 Sep 22
4
Crash report: regexpr("a{2-}", "")
Each of the following calls crash ("core dumps") R (R --vanilla) on various versions and OSes: regexpr("a{2-}", "") sub("a{2-}", "") gsub("a{2-}", "") EXAMPLES: > sessionInfo() R version 2.11.1 Patched (2010-09-16 r52949) Platform: i386-pc-mingw32 (32-bit) ... > regexpr("a{2-}", "") Assertion failed: iter->ma...
2010 Sep 22
4
Crash report: regexpr("a{2-}", "")
Each of the following calls crash ("core dumps") R (R --vanilla) on various versions and OSes: regexpr("a{2-}", "") sub("a{2-}", "") gsub("a{2-}", "") EXAMPLES: > sessionInfo() R version 2.11.1 Patched (2010-09-16 r52949) Platform: i386-pc-mingw32 (32-bit) ... > regexpr("a{2-}", "") Assertion failed: iter->ma...
2011 Sep 29
2
String manipulation with regexpr, got to be a better way
Help-Rs,   I'm doing some string manipulation in a file where I converted a string date in mm/dd/yyyy format and returned the date yyyy.   I've used regexpr (hat tip to Gabor G for a very nice earlier post on this function) in steps (I've un-nested the code and provided it and an example of what I did below.  My question is: is there a more efficient way to do this.  Specifically is there a way to use regexpr or some other string function to return...
2010 May 05
1
extracting a matched string using regexpr
...his apparently works, but is pretty ugly # some html test<-"</tr><tr><th>88958</th><th>Abcdsef</th><th>67.8S</th><th>68.9\nW</th><th>26m</th>" # a pattern to extract 5 digits > pattern<-"[0-9]{5}" # regexpr returns a start point[1] and an attribute "match.length" attr(,"match.length) # get the substring from the start point to the stop point.. where stop = start +length-1 > answer<-substr(test,regexpr(pattern,test)[1],regexpr(pattern,test)[1]+attr(regexpr(pattern,test),"match...
2007 Nov 02
1
R timeDate does not allow seconds?
...o me, but I've been unable to get seconds to work. I ended up with this format finally: "2007-10-31_16:20:22" Problem is I am unable to get it recognized as a date using timeDate(): R> timeDate(as.character(inputdate),format="%Y-%02m-%02d_%02H.%02M.%02S") Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") : missing value where TRUE/FALSE needed The R-help archives said something about non-standard formats casuing a problem, but I believe (short of the underscore) that its the seconds, not the delimiter that is causing...
2005 Aug 03
2
regexpr and portability issue
Dear all-- I am still forging my first arms with R and I am fighting with regexpr() as well as portability between unix and windoz. I need to extract barcodes from filenames (which are located between a double and single underscore) as well as the directory where the filename is residing. Here is the solution I came to: aFileName <- "/Users/marco/Desktop/diagnosticAnal...
2008 Aug 20
3
vector operation using regexpr?
Hi, Here's my problem... I have a data frame with three columns containing strings. The first columns is a simple character. I want to get the index of that character in the second column and use it to extract the item from the third column. I can do this using a scalar method. But I'm not finding a vector method. An example is below. col1 col2 col3 'L'
2007 Aug 02
4
Finding multiple characters in the same string
Hi I have this problem where I need to find if there is any numbers in a string, this is no problem if theres only one number per string. I would then simply use the regexpr() funtion togheter with the substring function to extract the number. But regexpr only picks one number per string either from the beginning or the end, but not multiple. Can this be done? And how for example My string <- "this1is2a3test" The result I want is an vector of c(1,2,3) /...
2008 Mar 06
1
invalid regular expression '[a-Z]'
...following error on OSX but not on WinXP and Linux? I've tried with a few different versions of R (v2.5.1, v2.6.1, v2.6.2, v2.7.0devel). The locale does not seem to affect the error, i.e. I've tested a few different and it is still only OSX that gives the error but not the other two. > regexpr("[a-Z]", "foo") Error in regexpr(pattern, text, extended, fixed, useBytes) : invalid regular expression '[a-Z]' > regexpr("[a-zA-Z]", "foo") [1] 1 attr(,"match.length") [1] 1 > regexpr("[A-z]", "foo") [1] 1...
2013 Jan 07
3
pattern matching
Hi, I have a simple question. Suppose I have a string "x$Expensive". I want to find the position of the $ in this string; i.e., I want a function that returns 2. I tried grep, regexpr, etc with no luck, unless I'm just using them incorrectly. Any suggestions? Thanks, Walt ________________________ Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 ________________________ (V) 609-936-8999 (F) 609-936-3733 walt at dataanalyticscorp.com...
2004 Mar 24
1
string problems ( grep and regepxr)
...quot; command, all OK. but here comes the problem... After finding the correct line(s) i need to find a substring inside each string. In this case "tabs" I think it represented by "\t" in the grep command trying to use grep in each string it only returns 1 ... Afterwards I tried regexpr command it returns the correct position of the substring that I am looking for but it only reports the first one. does regexpr only returns the first one ? Partial example: d5 = "load0004 node0014 0.05 0.014583333" "load0005 node0017 0.05 0.014583333&q...
2007 Jun 28
3
: regular expressions: escaping a dot
What's really the problem with: > regexpr( '\.odt$', "xxxxYodt", perl=TRUE ) Warning: '\.' is an unrecognized escape in a character string Warning: unrecognized escape removed from "\.odt$" [1] 5 attr(,"match.length") [1] 4 I know that I could use: > regexpr( '[.]odt$', "x...
2010 Jun 02
2
regexpr mystery can not remove trailing spaces
Dear all I encountered strange problem with regexpr replacement I made this character object str <- "02.06.10 12:40 " > str(str) chr "02.06.10 12:40 " I read in an object which seems to be quite similar > str(as.character(becva$V1)[1]) chr "02.06.10 12:40 " However I can not remove trailing s...
2012 Aug 21
7
Regular Expressions in grep
Dear r-help members, I have a number in the form of a string, say: a<-"-01020.909200" I'd like to extract "1020." as well as ".9092" Front<-grep(pattern="[1-9]+[0-9]*\\.", value=TRUE, x=a, fixed=FALSE) End<-grep(pattern="\\.[0-9]*[1-9]+", value=TRUE, x=a, fixed=FALSE) However, both strings give "-01020.909200", exactly