Regex for String

In the following string I would like to get the following:

Get this:

Business Machine.\nCombustion.\nFuel Cell.\nIndustrial.\nMedical.\nTransit.\nAquaculture.\nOther.

From this:

string(264) "required=0 changeable=0 show_at_reg_form=0 show_at_my_details_form=0 show_at_userlist_profile=0 show_at_userlist_card=0 values=Business Machine.\nCombustion.\nFuel Cell.\nIndustrial.\nMedical.\nTransit.\nAquaculture.\nOther. default_values= searcheable=1 cols=20 " 
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>

Open in new window

Thank you.
LVL 14
EMB01Asked:
Who is Participating?
 
käµfm³d 👽Commented:
How about this:

if (preg_match("/(?<=values=)([^.]|\.(?!\s*\w+=))+\./", $source, $match)) {
	echo $match[0];
}

Open in new window

0
 
Chris HarteThaumaturgeCommented:
I do not do regex, but if your structure of the string is always the same you could do something like this;
$whole_string = "required=0 changeable=0 show_at_reg_form=0 show_at_my_details_form=0 show_at_userlist_profile=0 show_at_userlist_card=0 values=Business Machine.\nCombustion.\nFuel Cell.\nIndustrial.\nMedical.\nTransit.\nAquaculture.\nOther. default_values= searcheable=1 cols=20";

$start_string = strstr($whole_string, "default_value", true);

$end_string = strstr($start_string, "Business");

print_r($end_string);

Open in new window

0
 
EMB01Author Commented:
I didn't test the non-regex solution, but the regex worked, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.