x <- c('/name12/?ad_2','/name13/?ad_3','/name14/?ad_4')sub("(\\?ad_)[0-9]+$", "\\1", x)sub("_[0-9]+$", "_", x)
Standard input is empty
[1] "/name12/?ad_" "/name13/?ad_" "/name14/?ad_" [1] "/name12/?ad_" "/name13/?ad_" "/name14/?ad_"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!