Is there guaranteed to be a line-break between each solution? Yep...
In javascript you can use one of the following solutions.
Using the split
method you can do the following:
results = myString.split(/[\r\n]+/);
Using the match()
method you can do the following, this will match the parts that are not linebreaks.
results = myString.match(/[^\r\n]+/g);
In php you accomplish your desired task using one of the following solutions.
$wanted = preg_split('~\R+(?!$)~u', $data);
print_r($wanted);
See live working demo
\R
matches a generic newline; that is, anything considered a linebreak sequence by Unicode. This includes all characters matched by \v
(vertical whitespace) and the multi character sequence \x0D\x0A
. To use properly you need to enable the u
modifier. The u
modifier turns on additional functionality of PCRE and Pattern strings are treated as UTF-8.
I used a negative lookahead after with $
(end of line) so that you are not including empty whitespace.
You can avoid using split and match using negation here.
$wanted = preg_match_all('~[^\r\n]+~', $data, $matches);
print_r($matches);
See live working demo
Output
Array
(
[0] => The study of standards for what is right and what is wrong is called _.
[1] => a. pure science
[2] => b. applied science
[3] => c. ethics
[4] => d. technology
[5] => ... unknown number of choices ...
[6] => ANS: C
)