Extract first N digits from a string

后端 未结 4 968
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 11:14

I want to extract just FIRST TWO DIGITS from some strings. Suppose the data is :

ABC Conference Room Monitor - Z5580J    
ABC 19 Monitor    
ABC 24 Monitor f         


        
4条回答
  •  情书的邮戳
    2020-12-18 12:05

    Package stringr perhaps allows for the cleanest solution:

    stringr::str_extract(string, "\\d{2}")
     "55" "19" "24" "24"
    

提交回复
热议问题