r - Regex to match strings that are all punctuation but not strings with punctuation containing other characters -


i have messy text responses i'm trying cleanup little. i'm using r , want match responses punctuation removal.

is there regexp can use match these:

!@#$ . ********** 

but not these:

hello. !asdf **********1 

i had tried

x[grepl("^[[:punct:]+]", x)] 

which matches punctuation @ first character punctuation character

simply use negation..

x[!grepl("\\w", x)]  

or

x[!grepl("[a-za-z]", x)]  

your regex x[grepl("^[[:punct:]+]", x)] should check punctuation exists @ start.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -