Jump to content

[SOLVED] extract quoted strings


rarebit

Recommended Posts

Hi,

Whats the best way to extract quoted strings?

Given the following example:

this isn't an "interesting example", but 'then what' would we expect?

The main problem is the single quote in "isn't", can this be (generally) caught because in this type of situation it is concatenated between other characters, whereas a string generally has whitespace on at least one side. This however wouldn't catch situations like:

I saw 'em 'ther day like...

Any suggestions?

Cheers

Link to comment
https://forums.phpfreaks.com/topic/136864-solved-extract-quoted-strings/
Share on other sites

I likes it, a lot!

Never used 'back references' before (ref), very useful.

As expected the following fails a little...

$string = "I saw 'em 'ther day like 'had bells' on they did \"that arh\" y'know! But 'hey what's thee' expect like?";
print $string."<br>";
preg_match_all('/\B(["\'])(.+?)\1\B/s', $string, $matches);
print_r($matches[0]);

 

VERY GOOD, CHEERS MR dARKwATER!

I'm thinking the issue revolves around contractions and was wondering if there were a finite number of generally used instances, but even I make 'em up as I go...

http://www.enchantedlearning.com/grammar/contractions/list.shtml

http://homeschool.consumerhelpweb.com/subjects/languagearts/commoncontractionssimple.htm

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.