I am trying to parse a text file in PHP and group the content based on string match.
Text sample:
xxxx xxxx xx xxxx xxx foo xxx xxx xxxxx
xxxx xx foo xxx xxx xxxxx
xx xxxxx xxxx xx xxx xx bar xx xxxx
xxxxxx xx xxxxx x xxxx bar
xxx xxxxx xx xx foo_sub1 xxx xxxx
xx foo_sub2 xxxxx xxx x xxxx
xxx xx foo1_sub1 xxx xxxx
xxxxx foo1_sub2 xxxxx xxx x xxxx
private function stringContains ($string, $substring){
if (preg_match("~\b$substring\b~", $string)) {
return true;
}
}
the problem is that if the substring is foo it will not return me foo_sub, any idea how to edit my regex to include any foo and foo_ but not foo1 or foo1_?
Thanks,