php - Find next word after colon in regex -
i getting result return of laravel console command
some text as: 'nerad'
now tried
$regex = '/(?<=\bsome text as:\s)(?:[\w-]+)/is';
preg_match_all( $regex, $d, $matches );
but returning empty. guess wrong single quotes, need change regex.. guess?
note no match because '
before nerad
not matched, nor checked lookbehind.
if need check context, avoid including match, in php regex, can done \k
match reset operator:
$regex = '/\bsome text as:\s*'\k[\w-]+/i';
see regex demo
the output array structure cleaner when using capturing group , may check unknown width context (lookbehind patterns fixed width in php pcre regex):
$re = '/\bsome text as:\s*\'\k[\w-]+/i'; $str = "some text as: 'nerad'"; if (preg_match($re, $str, $match)) { echo $match[0]; } // => nerad
see php demo
Comments
Post a Comment