Thanks Matt and Dirk. Both suggestions are good. I'll try one of them ( not sure which yet ) and let you know how it works out. Definitely it's not as as easy a problem as I originally thought. Thanks again.
Mark On Tue, Jan 13, 2015 at 9:41 AM, Matt D. <mat...@gmail.com> wrote: > On 1/13/2015 07:27, Mark Leeds wrote: > >> Hi All: I was trying to do something with regular expressions in Rcpp so >> I piggy backed >> heavily off of Dirk's boost.regex example in the Rcpp Gallery where he >> takes streams of digits and checks them for machine and human readability. >> > Hi! > >> >> My problem is actually pretty different and simpler. Essentially, if a >> character string ends in "rhofixed" or "norhofixed", then that part of the >> character string should be removed. The R code below illiustrates what I'm >> trying to do. >> >> But, when I write the Rcpp code to do the same thing and set >> Sys.setenv("PKG_LIBS"="-lboost_regex"), I don't get the same result. I >> don't know if it's due to the regex engine being different in boost or I >> could be doing something else wrong. Thanks for any help. >> > It does indeed seems simpler than an usual use case for regex. Hence, > perhaps you can go about it differently: > - use `boost::algorithm::ends_with` (from > <boost/algorithm/string/predicate.hpp>) > to check whether your predicate (i.e., a character string ends in > "rhofixed" or "norhofixed") holds > - if so, use the `erase` member function (http://en.cppreference.com/w/ > cpp/string/basic_string/substr) to get rid of the substring (note: if one > of the aforementioned predicates is satisfied, then you can trivially infer > how long is the substring subject to removal -- and can thus use, say, the > iterator-pair version, stepping backward from `std::end(your_string)` as > needed). > > HTH! > > Best, > > Matt > >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel