0

以下に示すような文字列に一致する正規表現を作成しました。

then "hello I am here" blah blah

また

then hello blah blah

の直後の単語を一致させようとしていthenます。上記の文字列の場合、予想される出力は次のとおりです。

"hello I am here"   //if the words are in quotes

また

hello

私はこの正規表現を試しまし&quot;(\w*[\s]*)*&quot;|(?<=\bthen\s)(\w+)た。オンラインでは正常に動作していますが、Firefox ではエラーが表示されます。エラー

ここに画像の説明を入力

4

1 に答える 1

1

試す

var regex = /then\s*(&quot;(.*?)&quot;|(\w*))\s*.*/

function getSomething(string){
    var arr = regex.exec(string);
    console.log(arr);
    return arr.length > 1 ? arr[1] : undefined;
}

デモ:フィドル

于 2013-05-01T07:24:14.817 に答える