[R] Logic with regexps

2010-06-12 Thread Ted Harding
Greetings, The following question has come up in an off-list discussion. Is it possible to construct a regular expression 'rex' out of two given regular expressions 'rex1' and 'rex2', such that a character string X matches 'rex' if and only if X matches 'rex1' AND X does not match 'rex2'? The

Re: [R] Logic with regexps

2010-06-12 Thread Prof Brian Ripley
I think you have missed grepl(), e.g. X[grepl(rex1, X) !grepl(rex2, X)] grepl is a fairly recent addition (2.9.0) that is used extensively in R's own text-processing operations (e.g. help files, utilities such as 'R CMD check'). On Sat, 12 Jun 2010, ted.hard...@manchester.ac.uk wrote:

Re: [R] Logic with regexps

2010-06-12 Thread Ted Harding
Thanks, Brian. I had indeed overlooked grepl() (too busy delving into the syntax summary)! That is certainly a useful shortcut of the construction I had used. Your Not in general implies that using grep() twice (in this example; more times in more complex combinations) is inevitable -- which of

Re: [R] Logic with regexps

2010-06-12 Thread Gabor Grothendieck
On Sat, Jun 12, 2010 at 5:38 AM, Ted Harding ted.hard...@manchester.ac.uk wrote: Greetings, The following question has come up in an off-list discussion. Is it possible to construct a regular expression 'rex' out of two given regular expressions 'rex1' and 'rex2', such that a character string

Re: [R] Logic with regexps

2010-06-12 Thread Ted Harding
Thanks, Gabor, for the initiation to perly regexps! I've only been used to extended ones till now. A pity, perhaps, that perl=TRUE is not an option for the likes of browseEnv(), help.search(), list.files() and ls() (which take extended regexps), but one can always assign the output and then