Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find word starting with $ from given string with angular 2

I want to find word starting with $.

var s = "$hello, this is a $test $john #doe";
var re = /(?:^|\W)#(\w+)(?!\w)/g, match, matches = [];
while (match = re.exec(s)) {
  matches.push(match[1]);
}

Above regex gives me word starting with #, But I can't use same regex for finding word starting with $.

So How can i find word starting with $ ??

like image 389
Aarsh Avatar asked Nov 20 '25 03:11

Aarsh


1 Answers

Please try this regex,

 var str = "$iPhone should be ab#le to complete and $delete items";
    alert(str.match(/(^|\s)\$(\w+)/g).map(function(v){return v.trim().substring(1);}));
    });
like image 79
Trusha Avatar answered Nov 22 '25 15:11

Trusha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!