Help with this reg. exp. in PHP
Posted
by Jonathan
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan
Published on 2010-05-29T18:52:02Z
Indexed on
2010/05/29
19:02 UTC
Read the original article
Hit count: 251
Hi, 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!
© Stack Overflow or respective owner