-1
According to the strings below, using preg_match, I need a Pattern that is able to separate what is inside and outside of simple quotes and remove $match[1] blank spaces from the end of the string. It is possible?
<?php
$string_1 = "Scorpions 'Scorpions Dynamite'";
$string_2 = "Scorpions 'Scorpions 'Dynamite''";
$pattern = "/(.*)'([^\']+)'/";
$s1 = preg_match ($patern, $string_1, $match);
$s2 = preg_match ($patern, $string_2, $match);
print_r ($s1);
print_r ($s2);
?>
Result of the above code:
s1 = array (
0 => 'Scorpions \'Scorpions Dynamite\'',
1 => 'Scorpions ',
2 => 'Scorpions Dynamite',
)
s2 = array (
0 => 'Scorpions \'Scorpions \'Dynamite\'',
1 => 'Scorpions \'Scorpions ',
2 => 'Dynamite',
)
With a lot of difficulty I arrived in this Pattern here, but it is not enough... I thank you for the help.
$pattern = "/(.*)'([^\']+)'/";
ADDENDUM :
What I need to do is modify the Pattern of such a foma that the $match[1] array will only show simple words, without blank spaces at the end [only alphanumeric characters], because as you can see, until a quote escaped to the match and reappeared in one of the indexes of the array and this gives error in a json application I have here.
So should be the exit on the two arrays:
array (
0 => 'Scorpions \'Scorpions Dynamite\'',
1 => 'Scorpions',
2 => 'Scorpions Dynamite',
)
array (
0 => 'Scorpions \'Scorpions \'Dynamite\'',
1 => 'Scorpions Scorpions',
2 => 'Dynamite',
)
I don’t know if I was clear, if you want to explain again