regex - Find location of $ in string -
based on advice here: find location of character in string, tried this:
> gregexpr(pattern ='$',"data.frame.name$variable.name") [[1]] [1] 30 attr(,"match.length") [1] 0 attr(,"usebytes") [1] true
but didn't work; note:
> nchar("data.frame.name$variable.name") [1] 29
how find location of $
in string?
the problem $
end-of-string marker in regex. try instead:
> gregexpr(pattern ='\\$',"data.frame.name$variable.name") [[1]] [1] 16 attr(,"match.length") [1] 1 attr(,"usebytes") [1] true
... gives right answer - i.e. 16
.
Comments
Post a Comment