Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
How do I rewrite my regular expression so that it works in Safari?

I created a function a while back that capitalizes a string. The function applies a regular expression to determine if the first alphanumeric character is preceded by a non-alphanumeric character. The search method returns the index of the first alphanumeric character, should that be the case. Otherwise, the function simply converts the first character of the string to an uppercase character.

function capitalize(string: string) {
  const match = string.search(/(?<=[^[a-z]|[0-9]\s])[a-z]|[0-9]/i);
  const index = match === -1 ? 0 : match;

  const characters = string.toLowerCase().split('');
  characters[index] = characters[index].toUpperCase();

  return characters.join('');
}

However, it turns out that this breaks in Safari, because the regular expression relies on a positive look-behind, and Safari does not support that, as far as I can tell.

How could I rewrite this regular expression, so that it works in Safari as well (no look-behind)?

I know that this can be done in multiple steps, but I would much prefer to use just one regular expression if that is possible.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!