tags:

views:

20

answers:

3

I need to find part of string which is equal to string till end of word.

Example i have texts:

  1. "Start play. I need..."
  2. "Start playstation play"
  3. "start play, work"
  4. "start player"
  5. "start pay with..."

Then i searching for "/^start play/'i" and found all phrases, but i need only phrases which ends with word play: 1, 3, 5

preg_match('/^start play/i', $text, $key_matches)

I can write in MySQL REGEXP it would be "^Start play[[:>:]]" [[:>:]] - means end of word, but i cant find how to write in PHP?

Can some one help me?

+3  A: 
preg_match('/^start play\b/i', $text, $key_matches)

\b matches a word boundary.

Cfreak
+1  A: 

\b is word boundary anchor

http://www.regular-expressions.info/wordboundaries.html

Mchl
A: 
/start play.+?\b/
stillstanding