I have a string like this: "21st-August-2017" and I would like to replace the "st" after 21 with "xx" so that the result is
"25xx-August-2017"
I have tried using regex repetition quantifiers, e.g.
gsub("st{1}", "xx", "21st-August-2017")
But this still replaces both instances of "st". How can I specify that it should match only the first instance of "st"?
Please use sub
instead of gsub
.
Replace the first occurrence of a pattern with
sub
or replace all occurrences withgsub
.
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