Reputation: 10551
Wow, I suck at regex
([*][.]+[*])
I'm trying to match text such as this:
*hello*
Upvotes: 0
Views: 46
Reputation: 152294
Just try with following regex:
(\*[^*]+\*)
In your regex you have [.]
which in fact searches for dots because in []
it loses its special context and is treated as a normal character. You should better use .+
then but it will match also *
characters. So use my above solution then.
Upvotes: 4
Reputation: 5127
This will capture
var text = "asdfasdf *hello*";
console.log( text.match(/([*][^*]+[*])/)[1]);
But that only grabs the first match;
If you want all matches
var text = "asdfasdf *hello* asdffdsa *asdf*";
var matches = text.match(/([*][^*]+[*])/g);
if(matches.length > 1) {
for(var i=1; i<matches.length; i++) {
console.log(matches[i]);
}
}
Upvotes: 1