I have a string like this:
Name: John Doe
Age: 23
Primary Language: English
Description: This is a multiline
description field that I want
to capture
Countr
Here's one solution: http://rubular.com/r/uDgXcIvhac.
\s*([^:]+?)\s*:\s*(.*(?:\s*(?!.*:).*)*)\s*
Note that I've used a negative lookahead assertion, (?!.*:)
. This is the only way you can check that the next line doesn't look like a new field, and at the same time continue where you left off. (This is why lookaheads and lookbehinds are known as zero-width assertions.)
EDIT: Removed bit about arbitrary-width lookaheads; I was mistaken. The above solution is fine.
Would PHP's strtok help you? You could use it with ":" as the delimeter/token and trim leading and trailing spaces to remove the unwanted new lines.
http://php.net/manual/en/function.strtok.php