Take the 2-minute tour ×

I am trying to find whole words e.g. 'Location:', 'Contact:', at the beginning of a string with preg_match.

Please could someone provide and quick example.


share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

starts (^) with word character (\w) and has one or more of them (+) and should be captured and stored in $matches (brackets)

$in = "First word is captured";
echo $matches[1];
share|improve this answer
Thanks, just the job. –  KennyJones Apr 9 '11 at 22:32
add comment

Your Answer


