[英]regex match a word after a particular word
我創建了一個正則表達式來匹配一個字符串,它可能類似於以下所示:
then "hello I am here" blah blah
要么
then hello blah blah
then
我正試圖匹配這個詞。 對於上述字符串,預期輸出為
"hello I am here" //if the words are in quotes
要么
hello
我嘗試了此正則表達式"(\\w*[\\s]*)*"|(?<=\\bthen\\s)(\\w+)
,該函數在網上正常運行,但在firefox中顯示錯誤。 錯誤
嘗試
var regex = /then\s*("(.*?)"|(\w*))\s*.*/
function getSomething(string){
var arr = regex.exec(string);
console.log(arr);
return arr.length > 1 ? arr[1] : undefined;
}
演示: 小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.