I am looking for a Regex for the below problem -
String - "32 - This-may-contain - hypen-as-well"
Divide from "-"
Result -> "32 ", " This-may-contain - hypen-as-well"
I was doing "32 - This-may-contain-hypen-as-well".split("-"); but the RHS can also contain hypens and I need to do more operations to join back the rhs with hypen.
use the regex as below in a match
const input = "32 - This-may-contain - hypen-as-well";
const result =input.match(/(.*?) - (.*)/).slice(1);
console.log(result);
but without regex it still can be done
const input = "32 - This-may-contain - hypen-as-well";
const [LHS, ...RHS] = input.split(' - ');
const result = [LHS, RHS.join(' - ')];
console.log(result);