gsub
Ruby gsub doesn’t escape single-quotes
\’ means $’ which is everything after the match. Escape the \ again and it works “Yaho’o”.gsub(“‘”, “\\\\'”)
Remove all punctuation except apostrophes in R
x <- “I like %$@to*&, chew;: gum, but don’t like|}{[] bubble@#^)( gum!?” gsub(“[^[:alnum:][:space:]’]”, “”, x) [1] “I like to chew gum but don’t like bubble gum” The above regex is much more straight forward. It replaces everything that’s not alphanumeric signs, space or apostrophe (caret symbol!) with an empty string.
How to remove unicode from string?
I just want to remove unicode <U+00A6> which is at the beginning of string. Then you do not need a gsub, you can use a sub with “^\\s*<U\\+\\w+>\\s*” pattern: q <-“<U+00A6> 1000-66329” sub(“^\\s*<U\\+\\w+>\\s*”, “”, q) Pattern details: ^ – start of string \\s* – zero or more whitespaces <U\\+ – a literal char sequence <U+ … Read more
Use gsub remove all string before first white space in R
Try this: sub(“.*? “, “”, D$name) Edit: The pattern is looking for any character zero or more times (.*) up until the first space, and then capturing the one or more characters ((.+)) after that first space. The ? after .* makes it “lazy” rather than “greedy” and is what makes it stop at the … Read more