Using Meta Characters in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Using Meta Characters in JavaScript

Good day bosses .. I am having a terrible time with this little code.. I am trying to use Regular Expression - Meta Characters to find "Le Guin" in the "wannabe" Array without having to type "Le Guin" directly in the Conditional statement, but through using some Meta-Characters.... Funny enough I tried this yesterday and it worked but I don't know what's wrong with it now... The "!/[Le *Guin]/" in the for Conditional statement is what am talking about... Please what could be wrong with the code <script> wannabe = ["Le Guin", "Ibrahim", "Ope", "You", "Le Guin", "Now", "Then", "Who", "Le Guin"]; for (a = 0; a < wannabe.length; ++a) { if (wannabe[a] == !/[Le*Guin]/) { document.write(a + ": " + "This is found at: " + a + "<br>") break } else { document.write(a + ": " + "not yet" + "<br>") } } </script>

21st Feb 2019, 9:42 AM
Algorithm
Algorithm - avatar
3 Answers
21st Feb 2019, 11:45 AM
Gordon
Gordon - avatar
+ 1
Gordon, your expression will match any character instead of a space, for example Le&Guin, for an exact search, you need to leave a space, but in this case wannabe[a].match(/L/) is enough.
28th Jul 2022, 6:15 PM
Solo
Solo - avatar
+ 1
Solo Thanks for pointing my mistake, learned from you ^^
29th Jul 2022, 3:42 AM
Gordon
Gordon - avatar