Wednesday, 15 April 2015

r - Regex and proper use of not -


I have the following vectors of variable names:

  vn & lt; - c ("id", "pid", "wave", "px", "pdobd", "pidob", "pdb", "psat3", "ppa 211", "psd23i19")   

I'm having trouble coming up with a proper regex which removes all the first p, but not for "pid".

  sub (???, "", vn) ## I tried "^ p [^ id]?" But there is no benefit ...   

Then, the result will look like this:

  c ("id", "pid", "wave", "    

You must use (negative lookhead)

  ^ p (?! Id)   

TRUE perl parameter

No comments:

Post a Comment