user3416431
user3416431

Reputation: 25

VB.Net Regex - Put spaces after number

I have a string like "7&9 Captial 06Actual 567".

I used the regex function:

Regex.Replace("7&9 Captial 06Actual 567", "[^\d-](?=[\d-])", "$& ")

Output - "7& 9 Captial 06Actual 567"

but I need the output like this - "7&9 Captial 06 Actual 567"

It has to put space after number, should not skip special character.

pls help, thanks

Upvotes: 0

Views: 225

Answers (1)

Toto
Toto

Reputation: 91385

Search for: (\d)([a-zA-Z])
and replace with: $1 $2

Updated according to comment below:

Search for: (?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)
Replace with: A single space

This will add a space between digit and letter or between letter and digit.

I don't know if VB supports lookaround

If you want to deal with unicode characters, use:

Search for: (?<=\p{N})(?=\p{L})|(?<=\p{L})(?=\p{N})
Replace with: A single space

Where \p{L} stands for any letter and \p{N} for any digit.

Upvotes: 1

Related Questions