How can I get the next word after pregmatch with PHP.

For example, If I have a string like this:

```
"This is a string, keyword next, some more text. keyword next-word."

```

I want to use a `preg_match` to get the next word after “keyword”, including if the word is hyphenated.

So in the case above, I want to return “next” and ”next-word”

I’ve tried :

```
$string = "This is a string, keyword next, some more text. keyword next-word.";

$keywords = preg_split("/(?<=\keyword\s)(\w+)/", $string);
print_r($keywords);

```

Which just returns everything and doesn’t seem to work at all.

Any help is much appreciated.
['https://Stackoverflow.com/questions/24226385', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3143218/']
Using your example this should work using [`preg_match_all`](http://www.php.net/manual/en/function.preg-match-all.php):

```
// Set the test string.
$string = "This is a string, keyword next, some more text. keyword next-word. keyword another_word. Okay, keyword do-rae-mi-fa_so_la.";

// Set the regex.
$regex = '/(?<=\bkeyword\s)(?:[\w-]+)/is';

// Run the regex with preg_match_all.
preg_match_all($regex, $string, $matches);

// Dump the resulst for testing.
echo '<pre>';
print_r($matches);
echo '</pre>';

```

And the results I get are:

```
Array
(
    [0] => Array
        (
            [0] => next
            [1] => next-word
            [2] => another_word
            [3] => do-rae-mi-fa_so_la
        )

)

```
Positive look behind is what you are looking for:

```
(?<=\bkeyword\s)([a-zA-Z-]+)

```

Should work perfect with `preg_match`. Use `g` modifier to catch all matches.

[Demo](http://regex101.com/r/nB9rU1)

Reference Question: [How to match the first word after an expression with regex?](https://stackoverflow.com/questions/546220/how-to-match-the-first-word-after-an-expression-with-regex)