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
Post a Comment