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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -