SyntaxFix
Write A Post
Hire A Developer
Questions
You can make the output just 4 and 24 using unlist:
unlist(gregexpr(pattern ='2',"the2quickbrownfoxeswere2tired")) [1] 4 24