Regex Expression inserting space after full stops + before Capital Letters

Hey there,

I’m hoping to find a solution with Regex to insert/replace instances from a string of text where “.Capital Letter” occurs eg:

“Hello, this text is an example.But I need to insert a space where there should be after full stops.Like this.But not insert a space after all full stops like in email address like this testing@dontinsertspacehere.com

I tried a simple replace “.” with ". " but the this results in the “.com” becoming “. com”

Any simple expression would be much appreciated!

On a side note - the above stems from formatting issues with using scraped text in the body of a JSON Htttp Post Request Eg:

"Here is example text I am scraping.

Inlcuding Line Breaks.

Like This."

This above text causing formatting issues when inserting into a body as a VAR and sending.
I am therefore replacing line breaks with “\t|\n|\r” but then this results in the space removal after full stops. My question is, any better techniques of passing this VAR into the body successfully retaining the line breaks and not having to format - asking for future solutions.

Many Thanks!

@Kyleb91

Try this

(?<=\.)(?=[A-Z])

System.Text.RegularExpressions.Regex.Replace(str,"(?<=\.)(?=[A-Z])"," ")

for the second part may be you can use something like this

System.Text.RegularExpressions.Regex.Replace(str,"\n+"," ")

this replaces multiple line breaks with a single space

if you want to replace any kind of multiple spaces then use [\n\s\t]+ in place of \n+

Hope this helps

cheers

1 Like

hi @Kyleb91

can you try this

System.Text.RegularExpressions.Regex.Replace(test,“(?!<^)(?=[A-Z])”," “).Replace(”. “,” ")

1 Like

well I want to keep the “.” :slight_smile: But thanks, the Regex is great

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.