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
Post a Comment