Ruby post title to slug

Is this Rails? (works in Sinatra) string.parameterize That’s it. For even more sophisticated slugging, see ActsAsUrl. It can do the following: “rock & roll”.to_url => “rock-and-roll” “$12 worth of Ruby power”.to_url => “12-dollars-worth-of-ruby-power” “10% off if you act now”.to_url => “10-percent-off-if-you-act-now” “kick it en Français”.to_url => “kick-it-en-francais” “rock it Español style”.to_url => “rock-it-espanol-style” “tell your … Read more

gsub() in R is not replacing ‘.’ (dot)

You may need to escape the . which is a special character that means “any character” (from @Mr Flick’s comment) gsub(‘\\.’, ‘-‘, x) #[1] “2014-06-09” Or gsub(‘[.]’, ‘-‘, x) #[1] “2014-06-09” Or as @Moix mentioned in the comments, we can also use fixed=TRUE instead of escaping the characters. gsub(“.”, “-“, x, fixed = TRUE)

Ruby multiple string replacement

Since Ruby 1.9.2, String#gsub accepts hash as a second parameter for replacement with matched keys. You can use a regular expression to match the substring that needs to be replaced and pass hash for values to be replaced. Like this: ‘hello’.gsub(/[eo]/, ‘e’ => 3, ‘o’ => ‘*’) #=> “h3ll*” ‘(0) 123-123.123’.gsub(/[()-,. ]/, ”) #=> “0123123123” … Read more

Replace specific characters within strings

With a regular expression and the function gsub(): group <- c(“12357e”, “12575e”, “197e18”, “e18947”) group [1] “12357e” “12575e” “197e18” “e18947” gsub(“e”, “”, group) [1] “12357” “12575” “19718” “18947” What gsub does here is to replace each occurrence of “e” with an empty string “”. See ?regexp or gsub for more help.