tags:

views:

41

answers:

1

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!

+1  A: 

Its a simple change:

preg_match('/(?:^[^(:"]+|(?<=^\()[^\s)]+)/', $var, $match);

I just added quotes inside the [^...] box, along with the colon and open parens.

swestrup