Skip to content
Back to formatted view

Raw Message

Message-ID: <1317815812.96272.YahooMailClassic@web28215.mail.ukl.yahoo.com>
Date: 2011-10-05T11:56:52Z
From: Jannis
Subject: help with regexp

Dear list memebers, 


I am stuck with using regular expressions.


Imagine I have a vector of character strings like:

test <- c('filename_1_def.pdf', 'filename_2_abc.pdf')

How could I use regexpressions to extract only the 'def'/'abc' parts of these strings?


Some try from my side yielded no results:

testresults <- grep('(?<=filename_[[:digit:]]_).{1,3}(?=.pdf)', perl = TRUE, value = TRUE)

Somehow I seem to miss some important concept here. Until now I always used nested sub expressions like:

testresults <- sub('.pdf$', '', sub('^filename_[[:digit:]]_', '' , test))


but this tends to become cumbersome and I was wondering whether there is a more elegant way to do this?



Thanks for any help

Jannis