Reputation: 390
I have some messy text responses that I'm trying to cleanup a little. I'm using R and want to match responses that are all punctuation for removal.
Is there a regexp I can use to match these:
!@#$
.
**********
But not these:
Hello.
!asdf
**********1
I had previously tried
x[grepl("^[[:punct:]+]", x)]
which only matches punctuation at first character with another punctuation character
Upvotes: 1
Views: 3807
Reputation: 174706
Simply use negation..
x[!grepl("\\w", x)]
or
x[!grepl("[a-zA-Z]", x)]
Your regex x[grepl("^[[:punct:]+]", x)]
should check for a punctuation exists at the start.
Upvotes: 3
Reputation: 67968
^[^\\w\\n]+$
You can use this.See demo.
https://regex101.com/r/cZ0sD2/6
Upvotes: 1