fork download
  1. replaceDash <- function(x) gsub("(\\w)-(?=\\w)", "\\1§", x, perl=T)
  2.  
  3. # these are all OK
  4. replaceDash("Hawaii-Five-O")
  5. ## [1] "Hawaii§Five§O"
  6. replaceDash("jack-of-all-trades")
  7. ## [1] "jack§of§all§trades"
  8. replaceDash("A-bomb")
  9. ## [1] "A§bomb"
  10. replaceDash("freakin-A")
  11. ## [1] "freakin§A"
  12.  
  13. # not the desired outcome
  14. replaceDash("jack-o-lantern") # FAILS - should be "jack§o§lantern"
  15. ## [1] "jack§o-lantern"
  16. replaceDash("Whack-a-Mole") # FAILS - should be "Whack§a§Mole"
  17. ## [1] "Whack§a-Mole"
Success #stdin #stdout 0.45s 79168KB
stdin
Standard input is empty
stdout
[1] "Hawaii§Five§O"
[1] "jack§of§all§trades"
[1] "A§bomb"
[1] "freakin§A"
[1] "jack§o§lantern"
[1] "Whack§a§Mole"