sm1l3y sm1l3y - 1 year ago 105
Javascript Question

JQUERY/JavaScript - RegEx everything after and including 3rd occurrence of character

I am trying to find some assistance in parsing out and replacing everything after (and including) the 3rd occurrence of a character with some text.

Here is an example of what I need accomplished:



Ive gotten thus far:

var theString = ('Bob,Jones,Suzy,Amy,Cindy,Jimmy');
theString = theString.replace('', '...');

Answer Source

You can do split + slice + join:

var s = 'Bob,Jones,Suzy,Amy,Cindy,Jimmy'
var r = s.split(',').slice(0,3).join(',')
//=> "Bob,Jones,Suzy"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download