0

I am trying to always convert a string based on the first 2 capitalized letters and then hyphenate those 2 words and ignore everything after.

so SourceSansPro-ExtraLight would be source-sans

I was able to use split to remove the hyphen and then ignore everything after it can't account for the other part, which is just paying attention to the first 2 capitalized words.

sal3jfc
  • 517
  • 4
  • 14
  • Does this answer your question? [Javascript Split string on UpperCase Characters](https://stackoverflow.com/questions/7888238/javascript-split-string-on-uppercase-characters) – SuperStormer Sep 02 '22 at 20:05

1 Answers1

1

Here is a way to do it with regex.

const str = 'SourceSansPro-ExtraLight';
const match = str.replace(/([A-Z][a-z]+)([A-Z][a-z]+).*/, '$1-$2');
console.log(match);
Rocky Sims
  • 3,523
  • 1
  • 14
  • 19