alyx
alyx

Reputation: 2733

Regular Expression: Match word and save anything else until space

I am trying to regex for words matching @food__ or #food__ in a string, so that I always match @food or #food and any other letters succeeding until a space. This is giving me errors:

preg_match_all('/\#/food/i', $unparsed, $parsed);

Also, how can I add conditions like matching: Food, FOOD & food ?

Upvotes: 0

Views: 227

Answers (1)

user142162
user142162

Reputation:

preg_match_all('/[#@]food\S*/i', $unparsed, $parsed);

Upvotes: 4

Related Questions