You're on the right track - the keyword you should be googling is Regular Expressions. R does support them in a more direct way than this using grep() and a few other alternatives.
Here's a detailed discussion: http://www.regular-expressions.info/rlanguage.html