I wish to know why I obtain two different output strings by using gsub and stringi. Does the metacharacter "." not include new lines in stringi? Does stringi read "line by line"?
By the way I did not find any way to perform the "correct" substitution with stringi so I needed to use gsub here.
string <- "is it normal?\n\nhttp://www.20minutes.fr"
> gsub(" .*?http"," http", string)
[1] "is http://www.20minutes.fr"
> stri_replace_all_regex(string, " .*?http"," http")
[1] "is it normal?\n\nhttp://www.20minutes.fr"
One way would be to set .
to also match line terminators instead of stopping at a line:
stri_replace_all_regex(string, " .*?http"," http",
opts_regex = stri_opts_regex(dotall = TRUE))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With