It is not clear in your question what consitutes a word. Are further underscores permitted? Are digits permitted? What about "words that consist of just the prefix", e.g. "abc_" or "xyz"?
Making the conservative assumptions (based on your examples) that you are expecting only letters from the English alphabet, at least one further character, and you don't care about case, you can simplify your regexp:
[regexp -nocase -- {\m(abc_|xyz_)[a-zA-Z]+} $str match]
This will set match to the matching word. You can replace the conents of the square brackets if your definition of a word differs from my assumptions.
Your second question about whether to prefer regexp to string functions will depend upon context, and could lead into subjective territory.
Some things to consider:
- Does performance really matter? Unless you are doing the search in a tight loop, or searching very long strings, I suspect any performance difference will not be relevant. Wait until you have a performance issue, then profile your application to see where the bottleneck is, then you can test alternative implementations.
- Convenience is going to depend upon the preference of the programmer(s) who have to write and maintain the code. Do they love/hate using regexps?
- Using a regexp is likely to offer more flexibility, but it can be at the cost of readability.
My recommendation would be to use whichever you are most comfortable with. Write a good set of unit tests for your code, then optimise later only if you have identified a bottleneck there during profiling.