mycodetree Posted November 4, 2011 Share Posted November 4, 2011 Question 1: $text = array("This is a string for demonstration testing"); $result = preg_grep("/test/",$text); In the above, preg_grep would hit on the text 'test', within the word 'testing'. My question is, how can I instruct the PCRE (with preg_grep preferably) engine to only hit on the text 'test' when it appears as its own word, and not a series of characters within another word? Question 2: $text = array("This is a test string for demonstration testing"); $result = preg_grep("/test/",$text); In the above text string, how can I instruct the PCRE (with preg_grep preferably) engine to hit on all instances of the character series 'test'? After it hits on the first character series, 'test', how can I use preg_grep to continue searching the string for other instances of 'test'? Question 3: Does anyone have any good Internet resources on Regex that doesn't require you to understand hieroglyphs? Quote Link to comment Share on other sites More sharing options...
ddubs Posted November 4, 2011 Share Posted November 4, 2011 preg_grep is for matching on elements of an input array: <?php $array = array('Test', 'testing', 'test', 'fail'); $result = preg_grep('/test/', $array); ?> $result will output: Array ( [1] => testing [2] => test ) Perhaps go into a bit more detail on what you are trying to accomplish with regex Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.