I'm wondering how to change this exact php regex feature into javascript?
$ismatch= preg_match('|She is a <span><b>(.*)</b></span>|si', $sentence, $matchresult);
if($ismatch)
{
$gender= $matchresult[1];
}
else{ //do other thing }
I'm wondering how to change this exact php regex feature into javascript?
$ismatch= preg_match('|She is a <span><b>(.*)</b></span>|si', $sentence, $matchresult);
if($ismatch)
{
$gender= $matchresult[1];
}
else{ //do other thing }
This is not quite trivial since JavaScript doesn't support the s
modifier.
The equivalent regex object would be
/She is a <span><b>([\s\S]*)<\/b><\/span>/i
The functionality of the code (extracting group 1 from the match if there is a match) would be done in JavaScript like this:
var myregexp = /She is a <span><b>([\s\S]*)<\/b><\/span>/i;
var match = myregexp.exec(subject);
if (match != null) {
result = match[1];
} else {
// do other thing
}