function is exactly what I was going to suggest after having read your original post since it is particularly appropriate for text chunks delimited by separators (although a capturing regex can of course also do it, as shown in the posts below). As a side note, have a look at predefined character classes, such as
, which can save you quite a bit of typing and make your regexes easier to read and understand.