Avatar of 1Cougar
1Cougar

asked on 

Javascript replace all "." except in one case...

Hello,

I would like to check some text for occurences of periods where there is a character directly after it and add a space.  For example:  "This is an example.And this is another ex. for you." should become "This is an example.  And this is another ex. for you."  So, just the space inserted when there is another character (not for "ex.").

Not sure how to do this...

Thanks in advance!
JavaScript

Avatar of undefined
Last Comment
Rob
Avatar of Argenti
Argenti
Flag of France image

Step 1. Replace all ". " occurrences with "."
Step 2. Replace all "." occurrences with ". "

:)
Avatar of Argenti
Argenti
Flag of France image

Additional info:

You can use (free editor) Notepad++ in order to count the existing/replaced occurrences in case of a dot with several spaces after (".   ")
Repeat Step 1. until no more ". " exist
Apply Step 2. once, so you will obtain only ". " (dot followed by one single space)
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of 1Cougar
1Cougar

ASKER

I was looking for the javascript so @tagit :  thank you...that was what I was looking for.

Cheers!
Avatar of Rob
Rob
Flag of Australia image

Sorry, got tht slightly wrong, should be:

replace(/\.([^ ]{1})/g,"\. $1");

Open in new window

JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo