Saturday 15 March 2014

php - Regex matching a character where its not surrounded by a space -


Well, this is a bit tricky with my limited regex experience and although I've spent googling the past 30 minutes, I suspect It is easy to find a little special for this.

What I really need to do is find a string for a - character and if there is no empty space around it , it should be ' Replace with - '. For example:

"Arooh Goggles - Black"

"Arooh Goggles-Black" and "Airho Goggles-Black"

I looked at lookhead

Any help appreciated - if it matters, then it is going to be used in PHP.

  preg_replace ('/ \ s * - \s * /', '-', $ Targets);    

No comments:

Post a Comment