2
I have a problem to solve and I can’t write the correct regex. I want to add the semicolon between two emails:
ex <- "[email protected] [email protected]"
#resultado esperado:
[1] "[email protected];[email protected]"
Thanks for your help!
2
I have a problem to solve and I can’t write the correct regex. I want to add the semicolon between two emails:
ex <- "[email protected] [email protected]"
#resultado esperado:
[1] "[email protected];[email protected]"
Thanks for your help!
6
Here it comes:
ex <- "[email protected] [email protected]"
# Com o gsub()
gsub(pattern = "[[:blank:]]",
replacement = ";",
x = ex)
# Com str_replace_all(), que eu prefiro
library(stringr)
str_replace_all(string = ex,
pattern = "[[:blank:]]",
replacement = ";")
You could do that too:
str_replace_all(string = ex,
pattern = "[ ]",
replacement = ";")
Or else this:
str_replace_all(string = ex,
pattern = "[[:space:] ]",
replacement = ";")
[[:blank:]]
works to eliminate all types of white space, including tabs, etc. With [ ]
(a gap between brackets) you only remove the same common space. And with [[:space:]]
it is possible to delete spaces, tabs and also line breaks.
-1
Another simpler option would be:
ex <- "[email protected] [email protected]"
new_ex <- gsub(" ", ";", ex)
new_ex
Browser other questions tagged r regex
You are not signed in. Login or sign up in order to post.
i was writing the [[:Blank:]] wrong and it wasn’t working. Thank you!
– Jessica Voigt