With reference to this SO question: Cutting a string at nth occurrence of a character
Have a slightly different question: Can this be done using regex?
"aa.bb.cc.dd.ee.xx" => "aa.bb.NN.dd.ee.ff"
(replacing only 3rd occurrence, all chars are random alphanumeric text )
NOTE: .split() .slice() .join() is a readable solution, regex seems possible and straightforward (I may be wrong). Eg: replacing the first two "aa." and "bb." with say 'AoA' and 'BoB', seems trivial:-
`"aa.bb.cc.dd.ee.xx".replace(/([^\.]*\.){2}/, 'AoA.BoB.')`
Edit: Since "." means 'matching anything' in regex, please use ";" (semicolon) instead. To make it more difficult, what if we have a string like this:
"ax;;cyz;def;eghi;xyzw" and we wanted to replace 3rd section (eg: cyz)