Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.