Home > Net >  Need regex to replace a single character in a pattern with three characters
Need regex to replace a single character in a pattern with three characters

Time:09-02

In the pattern below, I need to put a single space before and after the dash. The part numbers will differ in each replacement but the rest of the string is always the same. I know very little about regex but am using a Wordpress plugin to do this (the database is backed-up :) It's simply asking for the regex string/formula.

Part #8208-#8212 needs to be changed to Part #8208 - #8212

Thanks

CodePudding user response:

I think that should do the trick:

'Part #8208-#8212 needs to be changed to Part #8208 - #8212'
   .replace(/(\S)-(\S)/g, '$1 - $2')
  • Related