Extracting everything after first two words in R

jzurks

I am trying to extract all the info, using a regular expression in R, after the first number and first word of an entry in a data frame.

For example:

Header = 
c("2006 Volvo XC70", 
"2012 Ford Econoline Cargo Van E-250 Commercial", 
"2012 Nissan Frontier", 
"2012 Kia Soul 5dr Wagon Automatic")

I want to write a pattern that will grab Volvo XC70, or Econoline Cargo Van E-250 Commercial (everything after the year and make) from an entry in my "header" column so that I may run the function on my data frame and create a new "model" column. I can't figure out a pattern that will allow me to skip the first string of integers, then a space, then the first string of characters, and then a space, and then grab everything proceeding.

Any help would be appreciated. Thanks!

Avinash Raj

Just use sub.

sub("^\\d+\\s+\\w+\\s+", "", df$x)

Example:

x <- "2012 Ford Econoline Cargo Van E-250 Commercial"
sub("^\\d+\\s+\\w+\\s+", "", x)
# [1] "Econoline Cargo Van E-250 Commercial"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular expression to match everything after two words

From Dev

How to replace words after first two words

From Dev

Extracting first two words of a string in Javascript using regex

From Dev

First two letters from words Regex in R

From Dev

SQL Select between two spaces or everything after first if only one

From Dev

Ignore first two special characters, and grab everything after that

From Dev

VBA regex everything after words

From Dev

VBA regex everything after words

From Dev

Extracting everything between two symbols in a string

From Dev

Extracting everything between two symbols in a string

From Dev

Extracting first names in R

From Dev

Get everything after first character

From Dev

Extracting a paragraph between two key words in Perl

From Dev

Match everything between two words in Powershell

From Dev

Using sed to delete everything between two words?

From Dev

Match everything between two words in Powershell

From Dev

REGEX in R: extracting words from a string

From Dev

Finding and extracting words that include a punctuation expressions in R

From Dev

R gsub everything after blank

From Dev

Find everything after first comma in lines and remove it

From Dev

regex - delete everything after the first letter

From Dev

Get everything after first occurence of substring

From Dev

Grep regexp (linux) for extracting two words and storing them in variables

From Dev

How to remove everything after two different punctuations

From Dev

Catch everything between two same words multiple times

From Dev

Extracting equal rows of two data frames (in R)

From Dev

Extracting a string between other two strings in R

From Dev

R:Extracting words from one column into different columns

From Dev

Styling Two First Words With Spannable String

Related Related

  1. 1

    Regular expression to match everything after two words

  2. 2

    How to replace words after first two words

  3. 3

    Extracting first two words of a string in Javascript using regex

  4. 4

    First two letters from words Regex in R

  5. 5

    SQL Select between two spaces or everything after first if only one

  6. 6

    Ignore first two special characters, and grab everything after that

  7. 7

    VBA regex everything after words

  8. 8

    VBA regex everything after words

  9. 9

    Extracting everything between two symbols in a string

  10. 10

    Extracting everything between two symbols in a string

  11. 11

    Extracting first names in R

  12. 12

    Get everything after first character

  13. 13

    Extracting a paragraph between two key words in Perl

  14. 14

    Match everything between two words in Powershell

  15. 15

    Using sed to delete everything between two words?

  16. 16

    Match everything between two words in Powershell

  17. 17

    REGEX in R: extracting words from a string

  18. 18

    Finding and extracting words that include a punctuation expressions in R

  19. 19

    R gsub everything after blank

  20. 20

    Find everything after first comma in lines and remove it

  21. 21

    regex - delete everything after the first letter

  22. 22

    Get everything after first occurence of substring

  23. 23

    Grep regexp (linux) for extracting two words and storing them in variables

  24. 24

    How to remove everything after two different punctuations

  25. 25

    Catch everything between two same words multiple times

  26. 26

    Extracting equal rows of two data frames (in R)

  27. 27

    Extracting a string between other two strings in R

  28. 28

    R:Extracting words from one column into different columns

  29. 29

    Styling Two First Words With Spannable String

HotTag

Archive