merlin
merlin

Reputation: 2917

How to add whitespace around character?

I am looking for a regex that will add a space before and after the character with php:

/

It should not match if the string is a number.

E.g.

match: text/second but not: 001/303030

Unfortunately my regex know how is limited. How could this be done?

Upvotes: 0

Views: 106

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

You can use following regex in order to match your string:

"([a-zA-Z]+)(/)([a-zA-Z]+)"

And replace the captured group using a back reference:

"\1 \2 \3"

You can use preg_replace function to that aim.

Upvotes: 1

Related Questions