0

I am having a string like: $m-set 88829828277 very good he is. From this string I want to get the part after the second space. ie, I want to get: very good he is.
I tried using split(" ")[2] but it only gives one word: very.

Any help is greatly appreciated!
Thanks!

Ajit Kumar
  • 367
  • 1
  • 10
  • 35

1 Answers1

3

While you could split and join:

const input = '$m-set 88829828277 very good he is';
const splits = input.split(' ');
const output = splits.slice(2).join(' ');
console.log(output);

You could also use a regular expression:

const input = '$m-set 88829828277 very good he is';
const output = input.match(/\S+ \S+ (.+)/)[1];
console.log(output);

where the (.+) puts everything after the second space in a capture group, and the [1] accesses the capture group from the match.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320