[Solved] Complicated regex in PHP

try this:

$q1 = "{Hello|Hi} sir.";
$q2 = "{How are you?|How are you doing?}";

$q = substr($q1, 1, strpos($q1,'}')-1);
$q_end = substr($q1, strpos($q1, '}')+2);
$parts = explode('|',$q);

echo "<select name=\"q1\">\n";
foreach($parts as $part){
    echo "\t<option value=\"".strtolower($part)."\">$part</option>\n";
echo "</select>\n";
echo $q_end . "\n";

$q = substr($q2, 1, strpos($q2, '}')-1);
$parts = explode('|',$q);

echo "<select name=\"q2\">\n";
foreach($parts as $part){
    echo "\t<option value=\"".strtolower(substr(str_replace(' ','_',$part),0,strlen($part)-1))."\">$part</option>\n";
echo '</select>';


<select name="q1">
    <option value="hello">Hello</option>
    <option value="hi">Hi</option>
<select name="q2">
    <option value="how_are_you">How are you?</option>
    <option value="how_are_you_doing">How are you doing?</option>

Of course depending on how and where you’re getting your questions from and in what format you’ll have to fix accordingly. But this gives you a starting point and an idea of how to proceed

solved Complicated regex in PHP