开发者

Using Regexpr with $

开发者 https://www.devze.com 2023-04-13 10:04 出处:网络
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开

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

精彩评论

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

关注公众号