Help substituting numbers out of a character string

I have a data set that has data formatted in the following way: ### abc #-a
For Example:

1 abcde 1-A
2 abcde 2-A
3 abcde 1-B
...
350 abcde 1-A

I want to remove the leading numbers without and leaving the rest of the string alone. My first thought was gsub but that will replace all of the numbers including the ones following (such as 1-A). Any thoughts?

The regex "^\\d+\\s" will match the numbers and space after that, anchored to the beginning of the string. You can use it with the string manipulation function of your choice. Technically, if you use it with sub or other function that only does one replace, you don't need the ^ to anchor the regex to the beginning of the string, but it pays to be explicit when working with regexes.

2 Likes

THANK YOU! I'm not great at regex's and was having a terrible time trying to figure out exactly how to get it the right way!