Add a space after a ending dot of a sentence

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












How can I add a space after the ending dot of a sentence ? So dots like "1.2" should be unaffected. Also if there is already a space, then there should not be a space added.



text= "This is a sample text. Just 1.2 to test.To add a space after the dot...Okay."


Result:



text= "This is a sample text. Just 1.2 to test. To add a space after the dot... Okay."









share|improve this question



















  • 1




    Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
    – Kuba♦
    11 mins ago











  • @Kuba This is true. I will add some more details
    – james
    10 mins ago















up vote
3
down vote

favorite












How can I add a space after the ending dot of a sentence ? So dots like "1.2" should be unaffected. Also if there is already a space, then there should not be a space added.



text= "This is a sample text. Just 1.2 to test.To add a space after the dot...Okay."


Result:



text= "This is a sample text. Just 1.2 to test. To add a space after the dot... Okay."









share|improve this question



















  • 1




    Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
    – Kuba♦
    11 mins ago











  • @Kuba This is true. I will add some more details
    – james
    10 mins ago













up vote
3
down vote

favorite









up vote
3
down vote

favorite











How can I add a space after the ending dot of a sentence ? So dots like "1.2" should be unaffected. Also if there is already a space, then there should not be a space added.



text= "This is a sample text. Just 1.2 to test.To add a space after the dot...Okay."


Result:



text= "This is a sample text. Just 1.2 to test. To add a space after the dot... Okay."









share|improve this question















How can I add a space after the ending dot of a sentence ? So dots like "1.2" should be unaffected. Also if there is already a space, then there should not be a space added.



text= "This is a sample text. Just 1.2 to test.To add a space after the dot...Okay."


Result:



text= "This is a sample text. Just 1.2 to test. To add a space after the dot... Okay."






string-manipulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 10 mins ago

























asked 34 mins ago









james

691518




691518







  • 1




    Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
    – Kuba♦
    11 mins ago











  • @Kuba This is true. I will add some more details
    – james
    10 mins ago













  • 1




    Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
    – Kuba♦
    11 mins ago











  • @Kuba This is true. I will add some more details
    – james
    10 mins ago








1




1




Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
– Kuba♦
11 mins ago





Just for answerers sake, can you be more precise about the rules? Clearly not each dot is affected. And other exceptions (or not) come to my mind too e.g. "1.2", "...".
– Kuba♦
11 mins ago













@Kuba This is true. I will add some more details
– james
10 mins ago





@Kuba This is true. I will add some more details
– james
10 mins ago











4 Answers
4






active

oldest

votes

















up vote
1
down vote













StringReplace[StringReplace[text, "." -> ". "], ". " ~~ EndOfString -> "."]



"This is a sample text. Just to test. To add a space after the dot. Okay."







share|improve this answer



























    up vote
    1
    down vote













    StringReplace[text, 
    WordBoundary ~~ "." ~~ Except[WhitespaceCharacter, WordBoundary] :> ". "]



    "This is a sample text. Just to test. To add a space after the dot. Okay."



    Or



    StringReplace[text, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



    "This is a sample text. Just to test. To add a space after the dot. Okay."



    Both solutions correctly handle the cases when there already is a whitespace character after the dot:



    text2 = "This is a sample text. Just to test.To add a space after the dot. Okay.";

    StringReplace[text2, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



    "This is a sample text. Just to test. To add a space after the dot. Okay."






    share|improve this answer






















    • Thanks a lot. Can you also try the new sample text that I added to the question ?
      – james
      6 mins ago

















    up vote
    1
    down vote













    StringReplace[text, "." ~~a:Except[DigitCharacter|WhitespaceCharacter|"."] :> ". "<> a]



    "This is a sample text. Just 1.2 to test. To add a space after the
    dot... Okay."







    share|improve this answer






















    • Thanks a lot. Can you also try the new sample text that I added to the question ?
      – james
      6 mins ago










    • @james, just did.
      – kglr
      2 mins ago

















    up vote
    1
    down vote













    StringReplace[text, RegularExpression["(\w\.)(\w)"] -> "$1 $2"]


    "\w" means word characters, including letters, digits and the underscore _. "\." means a period literally. So the regular expression means to find a string pattern with length three: a word character followed by a period and followed by a word character.



    Parentheses mean a group, and "$n" where n is an integer represents contents in the n-th group.



    So the whole operation is to add a blank between the two groups after locating them by the string pattern.




    Update for the new string:



    StringReplace[text, RegularExpression["([a-zA-Z]\.+)([a-zA-Z])"] -> "$1 $2"]





    share|improve this answer






















    • Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
      – james
      28 mins ago










    • @james OK, let me add some explanations.
      – Î‘λέξανδρος Ζεγγ
      28 mins ago










    • Thank you very much for your explanation.
      – james
      6 mins ago











    • @james But you changed the problem?
      – Î‘λέξανδρος Ζεγγ
      5 mins ago










    • Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
      – james
      4 mins ago










    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "",
    contentPolicyHtml: "",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184998%2fadd-a-space-after-a-ending-dot-of-a-sentence%23new-answer', 'question_page');

    );

    Post as a guest






























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    StringReplace[StringReplace[text, "." -> ". "], ". " ~~ EndOfString -> "."]



    "This is a sample text. Just to test. To add a space after the dot. Okay."







    share|improve this answer
























      up vote
      1
      down vote













      StringReplace[StringReplace[text, "." -> ". "], ". " ~~ EndOfString -> "."]



      "This is a sample text. Just to test. To add a space after the dot. Okay."







      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        StringReplace[StringReplace[text, "." -> ". "], ". " ~~ EndOfString -> "."]



        "This is a sample text. Just to test. To add a space after the dot. Okay."







        share|improve this answer












        StringReplace[StringReplace[text, "." -> ". "], ". " ~~ EndOfString -> "."]



        "This is a sample text. Just to test. To add a space after the dot. Okay."








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 25 mins ago









        Chris Degnen

        21.5k23382




        21.5k23382




















            up vote
            1
            down vote













            StringReplace[text, 
            WordBoundary ~~ "." ~~ Except[WhitespaceCharacter, WordBoundary] :> ". "]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Or



            StringReplace[text, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Both solutions correctly handle the cases when there already is a whitespace character after the dot:



            text2 = "This is a sample text. Just to test.To add a space after the dot. Okay.";

            StringReplace[text2, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."






            share|improve this answer






















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago














            up vote
            1
            down vote













            StringReplace[text, 
            WordBoundary ~~ "." ~~ Except[WhitespaceCharacter, WordBoundary] :> ". "]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Or



            StringReplace[text, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Both solutions correctly handle the cases when there already is a whitespace character after the dot:



            text2 = "This is a sample text. Just to test.To add a space after the dot. Okay.";

            StringReplace[text2, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."






            share|improve this answer






















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago












            up vote
            1
            down vote










            up vote
            1
            down vote









            StringReplace[text, 
            WordBoundary ~~ "." ~~ Except[WhitespaceCharacter, WordBoundary] :> ". "]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Or



            StringReplace[text, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Both solutions correctly handle the cases when there already is a whitespace character after the dot:



            text2 = "This is a sample text. Just to test.To add a space after the dot. Okay.";

            StringReplace[text2, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."






            share|improve this answer














            StringReplace[text, 
            WordBoundary ~~ "." ~~ Except[WhitespaceCharacter, WordBoundary] :> ". "]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Or



            StringReplace[text, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."



            Both solutions correctly handle the cases when there already is a whitespace character after the dot:



            text2 = "This is a sample text. Just to test.To add a space after the dot. Okay.";

            StringReplace[text2, a : WordCharacter ~~ "." ~~ b : WordCharacter :> a <> ". " <> b]



            "This is a sample text. Just to test. To add a space after the dot. Okay."







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 8 mins ago

























            answered 22 mins ago









            Alexey Popkov

            37.9k4104259




            37.9k4104259











            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago
















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago















            Thanks a lot. Can you also try the new sample text that I added to the question ?
            – james
            6 mins ago




            Thanks a lot. Can you also try the new sample text that I added to the question ?
            – james
            6 mins ago










            up vote
            1
            down vote













            StringReplace[text, "." ~~a:Except[DigitCharacter|WhitespaceCharacter|"."] :> ". "<> a]



            "This is a sample text. Just 1.2 to test. To add a space after the
            dot... Okay."







            share|improve this answer






















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago










            • @james, just did.
              – kglr
              2 mins ago














            up vote
            1
            down vote













            StringReplace[text, "." ~~a:Except[DigitCharacter|WhitespaceCharacter|"."] :> ". "<> a]



            "This is a sample text. Just 1.2 to test. To add a space after the
            dot... Okay."







            share|improve this answer






















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago










            • @james, just did.
              – kglr
              2 mins ago












            up vote
            1
            down vote










            up vote
            1
            down vote









            StringReplace[text, "." ~~a:Except[DigitCharacter|WhitespaceCharacter|"."] :> ". "<> a]



            "This is a sample text. Just 1.2 to test. To add a space after the
            dot... Okay."







            share|improve this answer














            StringReplace[text, "." ~~a:Except[DigitCharacter|WhitespaceCharacter|"."] :> ". "<> a]



            "This is a sample text. Just 1.2 to test. To add a space after the
            dot... Okay."








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 4 mins ago

























            answered 15 mins ago









            kglr

            169k8192395




            169k8192395











            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago










            • @james, just did.
              – kglr
              2 mins ago
















            • Thanks a lot. Can you also try the new sample text that I added to the question ?
              – james
              6 mins ago










            • @james, just did.
              – kglr
              2 mins ago















            Thanks a lot. Can you also try the new sample text that I added to the question ?
            – james
            6 mins ago




            Thanks a lot. Can you also try the new sample text that I added to the question ?
            – james
            6 mins ago












            @james, just did.
            – kglr
            2 mins ago




            @james, just did.
            – kglr
            2 mins ago










            up vote
            1
            down vote













            StringReplace[text, RegularExpression["(\w\.)(\w)"] -> "$1 $2"]


            "\w" means word characters, including letters, digits and the underscore _. "\." means a period literally. So the regular expression means to find a string pattern with length three: a word character followed by a period and followed by a word character.



            Parentheses mean a group, and "$n" where n is an integer represents contents in the n-th group.



            So the whole operation is to add a blank between the two groups after locating them by the string pattern.




            Update for the new string:



            StringReplace[text, RegularExpression["([a-zA-Z]\.+)([a-zA-Z])"] -> "$1 $2"]





            share|improve this answer






















            • Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
              – james
              28 mins ago










            • @james OK, let me add some explanations.
              – Î‘λέξανδρος Ζεγγ
              28 mins ago










            • Thank you very much for your explanation.
              – james
              6 mins ago











            • @james But you changed the problem?
              – Î‘λέξανδρος Ζεγγ
              5 mins ago










            • Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
              – james
              4 mins ago














            up vote
            1
            down vote













            StringReplace[text, RegularExpression["(\w\.)(\w)"] -> "$1 $2"]


            "\w" means word characters, including letters, digits and the underscore _. "\." means a period literally. So the regular expression means to find a string pattern with length three: a word character followed by a period and followed by a word character.



            Parentheses mean a group, and "$n" where n is an integer represents contents in the n-th group.



            So the whole operation is to add a blank between the two groups after locating them by the string pattern.




            Update for the new string:



            StringReplace[text, RegularExpression["([a-zA-Z]\.+)([a-zA-Z])"] -> "$1 $2"]





            share|improve this answer






















            • Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
              – james
              28 mins ago










            • @james OK, let me add some explanations.
              – Î‘λέξανδρος Ζεγγ
              28 mins ago










            • Thank you very much for your explanation.
              – james
              6 mins ago











            • @james But you changed the problem?
              – Î‘λέξανδρος Ζεγγ
              5 mins ago










            • Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
              – james
              4 mins ago












            up vote
            1
            down vote










            up vote
            1
            down vote









            StringReplace[text, RegularExpression["(\w\.)(\w)"] -> "$1 $2"]


            "\w" means word characters, including letters, digits and the underscore _. "\." means a period literally. So the regular expression means to find a string pattern with length three: a word character followed by a period and followed by a word character.



            Parentheses mean a group, and "$n" where n is an integer represents contents in the n-th group.



            So the whole operation is to add a blank between the two groups after locating them by the string pattern.




            Update for the new string:



            StringReplace[text, RegularExpression["([a-zA-Z]\.+)([a-zA-Z])"] -> "$1 $2"]





            share|improve this answer














            StringReplace[text, RegularExpression["(\w\.)(\w)"] -> "$1 $2"]


            "\w" means word characters, including letters, digits and the underscore _. "\." means a period literally. So the regular expression means to find a string pattern with length three: a word character followed by a period and followed by a word character.



            Parentheses mean a group, and "$n" where n is an integer represents contents in the n-th group.



            So the whole operation is to add a blank between the two groups after locating them by the string pattern.




            Update for the new string:



            StringReplace[text, RegularExpression["([a-zA-Z]\.+)([a-zA-Z])"] -> "$1 $2"]






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 3 mins ago

























            answered 31 mins ago









            Αλέξανδρος Ζεγγ

            3,0991927




            3,0991927











            • Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
              – james
              28 mins ago










            • @james OK, let me add some explanations.
              – Î‘λέξανδρος Ζεγγ
              28 mins ago










            • Thank you very much for your explanation.
              – james
              6 mins ago











            • @james But you changed the problem?
              – Î‘λέξανδρος Ζεγγ
              5 mins ago










            • Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
              – james
              4 mins ago
















            • Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
              – james
              28 mins ago










            • @james OK, let me add some explanations.
              – Î‘λέξανδρος Ζεγγ
              28 mins ago










            • Thank you very much for your explanation.
              – james
              6 mins ago











            • @james But you changed the problem?
              – Î‘λέξανδρος Ζεγγ
              5 mins ago










            • Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
              – james
              4 mins ago















            Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
            – james
            28 mins ago




            Awesome ! Thanks a lot ! Could you just add one or two comments about the terms withing the RegularExpression function ? I don't quite understand how you did it. Thanks !
            – james
            28 mins ago












            @james OK, let me add some explanations.
            – Î‘λέξανδρος Ζεγγ
            28 mins ago




            @james OK, let me add some explanations.
            – Î‘λέξανδρος Ζεγγ
            28 mins ago












            Thank you very much for your explanation.
            – james
            6 mins ago





            Thank you very much for your explanation.
            – james
            6 mins ago













            @james But you changed the problem?
            – Î‘λέξανδρος Ζεγγ
            5 mins ago




            @james But you changed the problem?
            – Î‘λέξανδρος Ζεγγ
            5 mins ago












            Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
            – james
            4 mins ago




            Kuba's comment made me realize that there is actually more to the question that I thought, and that I need to be more specific.
            – james
            4 mins ago

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184998%2fadd-a-space-after-a-ending-dot-of-a-sentence%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery