Reposition a word inside a string in r

I have a string vector that looks like this:

> string_vec [1] "XXX" "Snakes On A Plane" "Mask of the Ninja" "Ruslan" [5] "Kill Switch" "Buddy Holly Story, The" "Believers, The" "Closet, The" [9] "Eyes of Tammy Faye, The" "Gymnast, The" "Hunger, The" 

At the end there are some names containing ", The". I want to remove the comma and space and move "The" in front of the rest of the text.

For example, "Buddy Holly Story, The" becomes "The Buddy Holly Story".

Isolation of drawing records was simple:

 string_vec[grepl("[Aa-zZ]+, The", string_vec) == TRUE] 

How to change position now?

data

 string_vec <- c("XXX", "Snakes On A Plane", "Mask of the Ninja", "Ruslan", "Kill Switch", "Buddy Holly Story, The", "Believers, The", "Closet, The", "Eyes of Tammy Faye, The", "Gymnast, The", "Hunger, The") 
+5
source share
1 answer

You may try

 sub('^(.*), The', 'The \\1', string_vec) #[1] "XXX" "Snakes On A Plane" "Mask of the Ninja" #[4] "Ruslan" "Kill Switch" "The Buddy Holly Story" #[7] "The Believers" "The Closet" "The Eyes of Tammy Faye" #[10] "The Gymnast" "The Hunger" 
+8
source

All Articles