how to get a string using match function in javascript -


i ma trying string starting * , ending on * using match function.i getting array of strings not 1 string. code

str="==quotes==* thought going -- shouldn't @ christmastime -- next messiah.** on [[barack obama]]"  rege=/\* \w*/gi newarr=str.match(rege) console.log(newarr) 

your regex off. match between 2 asterisks, you're looking /\*([^*]*)\*/gi:

str = "==quotes==* thought going -- shouldn't @ christmastime -- next messiah.** on [[barack obama]]";  rege = /\*([^*]*)\*/gi;  newarr = str.match(rege);  console.log(newarr[0]);

note .match() returns array of matches. in order first match, can access first index [0] above.

hope helps! :)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -