简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM