That was a bit tough to read OP, so please forgive me if I misunderstand. But I'm about 90% sure that what you want is called a "Regular Expression". They aren't that easy to use at first but they are definiatly worth learning: http://www.cplusplus.com/reference/regex/