"I like your {car, house, cat, forum} a lot, but I don't like commas in parentheses.
It would be easy find and replace if there weren't any commas outside of the brackets which I don't want to find (and replace). I tried this PHP script with regex and it finds me "{car, " what is correct.
Code: Select all
$lines = file ('test.txt');
foreach ($lines as $line_num => $line) {
$suchmuster = '#{[\w\s]+,\s#'; //'#(?<={[\w\s]+),\s(?=\w+|})#';
$ersetzung = '|';
//echo preg_replace($suchmuster, $ersetzung, $line);
preg_match($suchmuster, $line, $treffer);
echo $treffer[0]."<br>";
}Code: Select all
$lines = file ('test.txt');
foreach ($lines as $line_num => $line) {
$suchmuster = '#{(?<=[\w\s]+),\s#'; //'#(?<={[\w\s]+),\s(?=\w+|})#';
$ersetzung = '|';
//echo preg_replace($suchmuster, $ersetzung, $line);
preg_match($suchmuster, $line, $treffer);
echo $treffer[0]."<br>";
}