gsub

Use gsub remove all string before first numeric character

為{幸葍}努か 提交于 2020-11-28 07:43:10
问题 Use gsub remove all string before first white space in R In this example, we try to remove everything before a space with sub(".*? (.+)", "\\1", D$name) . I'm looking for something really similar but I'm not really familiar with regex. I want to delete everything before the first numeric character but without remove it For example with: x <- c("lala65lolo","papa3hihi","george365meumeu") I want: > "65lolo","3hihi", "365memeu" 回答1: You may use > x <- c("lala65lolo","papa3hihi","george365meumeu"

Use gsub remove all string before first numeric character

人走茶凉 提交于 2020-11-28 07:42:25
问题 Use gsub remove all string before first white space in R In this example, we try to remove everything before a space with sub(".*? (.+)", "\\1", D$name) . I'm looking for something really similar but I'm not really familiar with regex. I want to delete everything before the first numeric character but without remove it For example with: x <- c("lala65lolo","papa3hihi","george365meumeu") I want: > "65lolo","3hihi", "365memeu" 回答1: You may use > x <- c("lala65lolo","papa3hihi","george365meumeu"

Matching a word after another word in R regex

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-08 20:35:39
问题 I have a dataframe in R with one column (called 'city') containing a text string. My goal is to extract only one word ie the city text from the text string. The city text always follows the word 'in', eg the text might be: 'in London' 'in Manchester' I tried to create a new column ('municipality'): df$municipality <- gsub(".*in ?([A-Z+).*$","\\1",df$city) This gives me the first letter following 'in', but I need the next word (ONLY the next word) I then tried: gsub(".*in ?([A-Z]\w+))") which