开发者

Using Regexpr with $

Just a quick question, does anyone know how to use regexpr with "\$" ? Essentially, I want to parse out strings and figure out what numeric value came after the \$ (for example "Get $50 off on p开发者_开发知识库urchases of new bed frames").


In regular expressions, $ would denote the end of the string, and so if you want to match an actual $, you'd need to "escape" it, like \$.

In grep in R, you need to use \\, as follows:

x <- "Get $50 off on purchases of new bed frames"
grep("\\$\\d+", x)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜