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

sql - VB.NET Operand type clash: date is incompatible with int error -

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

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -