Reputation: 8754
i don't know about regular expressions, I asked here for one that: gets either anything up to the first parenthesis/colon or the first word inside the first parenthesis. This was the answer:
preg_match('/(?:^[^(:]+|(?<=^\\()[^\\s)]+)/', $var, $match);
I need an improvement, I need to get either anything up to the first parenthesis/colon/quotation marks or the first word inside the first parenthesis.
So if I have something like:
$var = 'story "The Town in Hell"s Backyard'; // I get this: $match = 'story';
$var = "screenplay (based on)"; // I get this: $match = 'screenplay';
$var = "(play)"; // I get this: $match = 'play';
$var = "original screen"; // I get this: $match = 'original screen';
Thanks!
Upvotes: 0
Views: 90
Reputation: 4209
Its a simple change:
preg_match('/(?:^[^(:"]+|(?<=^\()[^\s)]+)/', $var, $match);
I just added quotes inside the [^...]
box, along with the colon and open parens.
Upvotes: 1