Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text that follows a regex pattern match

I'm struggling to find out how I can get the text after a regex match (until the end of word).

Ex 1:
Input: my home
Regex: /hom/
Result: e

Ex 2:
Input: soulful
Regex: /soul/
Result: ful

like image 933
Jakub Fedor Avatar asked Sep 16 '25 11:09

Jakub Fedor


1 Answers

You can use:

$str = 'soulful';
$reg = '/soul(\w+)/';
if ( preg_match($reg, $str, $m) )
   print_r ($m);

OUTPUT

Array
(
    [0] => soulful
    [1] => ful
)
like image 154
anubhava Avatar answered Sep 19 '25 01:09

anubhava