将这个php正则表达式转换为javascript


convert this php regex to javascript

我想知道如何将这个精确的php正则表达式功能更改为javascript?

$ismatch= preg_match('|She is a <span><b>(.*)</b></span>|si', $sentence, $matchresult);
if($ismatch)
{
      $gender= $matchresult[1];
}
else{ //do other thing }

这并不是一件小事,因为JavaScript不支持s修饰符。

等效的regex对象是

/She is a <span><b>(['s'S]*)<'/b><'/span>/i

代码的功能(如果有匹配,则从匹配中提取组1)将在JavaScript中完成,如下所示:

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
}