[solved]Keeping everything between double quotes

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

[solved]Keeping everything between double quotes

Post by dreamline »

Hi guyz,
Ive tried to get the regex to work so that only text between double quotes is splitted with the preg_split function, but it's final expression i'm having trouble with. Here's my code:

Code: Select all

$test = 'This is "just" a test. But "hopefully" some1 will get it to "work!';
$string1=preg_split('/(\".*?\")+(.*?)/',$test,-1,PREG_SPLIT_NO_EMPTY);
$pattern = '/.*?"(.*?)"/';
$string= preg_split ($pattern, $test, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Output: Array ( [0] => just [1] => hopefully [2] => some1 will get it to "work! )

So my problem is that the last piece of text is splitted into the array while I only want "just" and "hopefully" in array.

Hopefully someone can help me on this last part of the regex expression..

Thanks.. :D
Last edited by dreamline on Thu Apr 13, 2006 11:49 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You don't need preg_split(), just use preg_match_all().
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Thanks feyd... That worked.. :) Still figuring out regex and their functions.. LOL..

But thanks a bundle it works now.. :D
Post Reply