0

Why this code don't take all quotated words?

It only takes a first word in the innerHTML. And how to find all words between single and double quotations and how to shorten this js code more simple for keywords. https://code.sololearn.com/WvB2F1VEyyLv/?ref=app https://code.sololearn.com/W2G755S2tCM5/?ref=app

8th Jun 2021, 8:51 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
3 Answers
+ 2
Use new RegExp("(['\"]).*\\1", "g"); For the keywords modify your line 13 to: a[i].innerHTML=a[i].innerHTML.replace(/\b(abstract|arguments|await*|boolean|break|byte|case|catch|char|class*|const|continue|debugger|default|delete|do|double|else|enum*|eval|export*|extends*|false|final|finally|float|for|function|goto|if|implements|import*|in|instanceof|int|interface|let*|long|native|new|null|package|private|protected|public|return|short|static|super*|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with|yield)\b/gi,"<cord>$1</cord>"); Then you don't need mapobj in line 3
8th Jun 2021, 9:13 AM
Hape
Hape - avatar
+ 1
match only returns the first word that it matches . If you want to get all words use a flag "g" . Eg , new RegExp("'.*'","g");
8th Jun 2021, 9:10 AM
Abhay
Abhay - avatar
+ 1
Thank you Hape and Abhay
8th Jun 2021, 9:56 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar