0

In R, I need to remove string that exceeds the length of 7 characters, from a column in a data frame. My code is,

memos.to <- as.data.frame(apply(memos.to,2,function(x)gsub('/^[a-zA-Z0-9]{7,}$/', NA ,x)))

and it doesn't seem to work. What's wrong here?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
user3424107
  • 117
  • 1
  • 5

1 Answers1

0

The easiest way is to just check the string length.
Don't know R lang, but all things being equal, if it conforms to the minimal modern regex's

One of these should match as far as regex is concerned

/.{8,}/ using Dot-all modifier as external flag
or
/(?s).{8,}/
or
/[\S\s]{8,}/ if Dot-all not available

if you are only considering [a-zA-Z0-9] chars
/^[a-zA-Z0-9]{8,}$/