Jump to content

Regex problem


gunjanamit

Recommended Posts

Take a look at this example, or..... you want to be something else ?

<?php
$pattern = '/(?<=Replaced )(?=(\w+))/';
$str = 'Replaced disk, Replaced floppy, Replaced memory';
if(preg_match_all($pattern, $str,$matches)){
  echo '<pre>'.print_r($matches[1], true).'</pre>';
}
else {
    echo 'No match';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/266045-regex-problem/#findComment-1363353
Share on other sites

What do you mean ? Did you loop it ?

For example:


$newItems = array('computer','RAM', 'CD Rom');
$pattern = '/(?<=Replaced )(?=(\w+))/';
$str = 'Replaced disk, Replaced floppy, Replaced memory';
if(preg_match_all($pattern, $str,$matches)){
for($i=0;$i<count($newItems);$i++){
  $matches[1][$i] = $newItems[$i]; 
}
echo '<pre>'.print_r($matches[1], true).'</pre>';

}

 

Link to comment
https://forums.phpfreaks.com/topic/266045-regex-problem/#findComment-1363550
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.