Regular Expression to match dot separated list with no dot on the end and allow asterisk at the end












0















I have the following input strings and I need a regex to validate the input.



test.test = OK
test.test.1 = OK
test.text* = OK

test.test. = NO
test.test.* = NO
test = NO


This is my regex, it works but does not successful validate the input as wished:



^[a-z0-9*.-_.:]+$


How can I get it work?










share|improve this question

























  • What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

    – Wiktor Stribiżew
    Nov 27 '18 at 9:03













  • Could you clarify the criteria for your regex, please? It's not this obvious.

    – reartnew
    Nov 27 '18 at 9:03











  • @WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

    – Dino
    Nov 27 '18 at 9:06
















0















I have the following input strings and I need a regex to validate the input.



test.test = OK
test.test.1 = OK
test.text* = OK

test.test. = NO
test.test.* = NO
test = NO


This is my regex, it works but does not successful validate the input as wished:



^[a-z0-9*.-_.:]+$


How can I get it work?










share|improve this question

























  • What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

    – Wiktor Stribiżew
    Nov 27 '18 at 9:03













  • Could you clarify the criteria for your regex, please? It's not this obvious.

    – reartnew
    Nov 27 '18 at 9:03











  • @WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

    – Dino
    Nov 27 '18 at 9:06














0












0








0








I have the following input strings and I need a regex to validate the input.



test.test = OK
test.test.1 = OK
test.text* = OK

test.test. = NO
test.test.* = NO
test = NO


This is my regex, it works but does not successful validate the input as wished:



^[a-z0-9*.-_.:]+$


How can I get it work?










share|improve this question
















I have the following input strings and I need a regex to validate the input.



test.test = OK
test.test.1 = OK
test.text* = OK

test.test. = NO
test.test.* = NO
test = NO


This is my regex, it works but does not successful validate the input as wished:



^[a-z0-9*.-_.:]+$


How can I get it work?







c# regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 9:07







Dino

















asked Nov 27 '18 at 8:59









DinoDino

12719




12719













  • What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

    – Wiktor Stribiżew
    Nov 27 '18 at 9:03













  • Could you clarify the criteria for your regex, please? It's not this obvious.

    – reartnew
    Nov 27 '18 at 9:03











  • @WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

    – Dino
    Nov 27 '18 at 9:06



















  • What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

    – Wiktor Stribiżew
    Nov 27 '18 at 9:03













  • Could you clarify the criteria for your regex, please? It's not this obvious.

    – reartnew
    Nov 27 '18 at 9:03











  • @WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

    – Dino
    Nov 27 '18 at 9:06

















What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

– Wiktor Stribiżew
Nov 27 '18 at 9:03







What is the second regex? It is not quite clear what the rule related to * is. I tried now with ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$, no idea if you meant that . and * cannot appear next to each other (or consecutive . and * are not allowed). You say allow asterisk at the end, but you also state that test.test.* is a no match.

– Wiktor Stribiżew
Nov 27 '18 at 9:03















Could you clarify the criteria for your regex, please? It's not this obvious.

– reartnew
Nov 27 '18 at 9:03





Could you clarify the criteria for your regex, please? It's not this obvious.

– reartnew
Nov 27 '18 at 9:03













@WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

– Dino
Nov 27 '18 at 9:06





@WiktorStribiżew your regex is working. Please put is as answer and I will accept it.

– Dino
Nov 27 '18 at 9:06












3 Answers
3






active

oldest

votes


















1














You may use



^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$


See the regex demo (at regexstorm, line endings are CRLF and r? is used for the multiline string demo purpose only).



Details





  • ^ - start of string


  • (?!.*[.*]{2}) - no two consecutive . and * are allowed


  • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -


  • (?:.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of



    • . - a dot


    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -




  • $ - end of string.






share|improve this answer





















  • 2





    @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

    – Wiktor Stribiżew
    Nov 27 '18 at 10:52






  • 3





    @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

    – Wiktor Stribiżew
    Nov 27 '18 at 11:03





















1














I think this will solve your problem.



^[a-z0-9]+.[a-z0-9]+((.[a-z0-9]+)|*)?$



Explanation




^ - Start of the string.



[a-z0-9] - any of the character in this range will be valid.



+ - One or more.



. - Matches literal . (period).



((.[a-z0-9]+)|*)? -



    (.[a-z0-9]+) - this sub-group checks for . followed by any digit or characters
* - matches for asterisk
? - make the preceding group optional.


$ - Anchor to the end of line






share|improve this answer


























  • It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

    – Code Maniac
    Nov 29 '18 at 4:33













  • Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

    – Pushpesh Kumar Rajwanshi
    Nov 29 '18 at 7:18



















0














From your given valid and invalid sample of text, I am concluding following things,




  1. The text will contain word characters.

  2. The word characters can be separated by single dot. Like this abc.xyz or aaa.bbb.ccc

  3. Dot character can't be the first or last character. This is not ok .abc or abc.aaa.

  4. Optionally star (asterisk) character can only appear as the last character. Hence test.text* is fine because test.text is fine but test.text.* is not fine because test.text. is not fine.


Considering these rules, you can use following regex,



^w+(.w+)*(?<!.)[*]?$


Explanation:





  • ^ --> Start of string


  • w+ --> match a word of one or more length


  • (.w+)* --> Match further word characters zero or more preceded by a single literal dot zero or more times.


  • (?<!.)[*]? --> asterisk character can optionally be present at the end of string which should not be preceded by a literal dot


  • $ --> End of input.


Demo






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    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%2fstackoverflow.com%2fquestions%2f53495945%2fregular-expression-to-match-dot-separated-list-with-no-dot-on-the-end-and-allow%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You may use



    ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$


    See the regex demo (at regexstorm, line endings are CRLF and r? is used for the multiline string demo purpose only).



    Details





    • ^ - start of string


    • (?!.*[.*]{2}) - no two consecutive . and * are allowed


    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -


    • (?:.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of



      • . - a dot


      • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -




    • $ - end of string.






    share|improve this answer





















    • 2





      @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

      – Wiktor Stribiżew
      Nov 27 '18 at 10:52






    • 3





      @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

      – Wiktor Stribiżew
      Nov 27 '18 at 11:03


















    1














    You may use



    ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$


    See the regex demo (at regexstorm, line endings are CRLF and r? is used for the multiline string demo purpose only).



    Details





    • ^ - start of string


    • (?!.*[.*]{2}) - no two consecutive . and * are allowed


    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -


    • (?:.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of



      • . - a dot


      • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -




    • $ - end of string.






    share|improve this answer





















    • 2





      @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

      – Wiktor Stribiżew
      Nov 27 '18 at 10:52






    • 3





      @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

      – Wiktor Stribiżew
      Nov 27 '18 at 11:03
















    1












    1








    1







    You may use



    ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$


    See the regex demo (at regexstorm, line endings are CRLF and r? is used for the multiline string demo purpose only).



    Details





    • ^ - start of string


    • (?!.*[.*]{2}) - no two consecutive . and * are allowed


    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -


    • (?:.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of



      • . - a dot


      • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -




    • $ - end of string.






    share|improve this answer















    You may use



    ^(?!.*[.*]{2})[a-z0-9*_:-]+(?:.[a-z0-9*_:-]+)+$


    See the regex demo (at regexstorm, line endings are CRLF and r? is used for the multiline string demo purpose only).



    Details





    • ^ - start of string


    • (?!.*[.*]{2}) - no two consecutive . and * are allowed


    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -


    • (?:.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of



      • . - a dot


      • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -




    • $ - end of string.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 27 '18 at 10:48

























    answered Nov 27 '18 at 9:09









    Wiktor StribiżewWiktor Stribiżew

    319k16140222




    319k16140222








    • 2





      @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

      – Wiktor Stribiżew
      Nov 27 '18 at 10:52






    • 3





      @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

      – Wiktor Stribiżew
      Nov 27 '18 at 11:03
















    • 2





      @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

      – Wiktor Stribiżew
      Nov 27 '18 at 10:52






    • 3





      @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

      – Wiktor Stribiżew
      Nov 27 '18 at 11:03










    2




    2





    @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

    – Wiktor Stribiżew
    Nov 27 '18 at 10:52





    @PushpeshKumarRajwanshi Let OP use it and we'll see. I can fix the pattern if OP comes back to adjust the requirements. I only posted since my suggestion worked.

    – Wiktor Stribiżew
    Nov 27 '18 at 10:52




    3




    3





    @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

    – Wiktor Stribiżew
    Nov 27 '18 at 11:03







    @PushpeshKumarRajwanshi You will get upvotes if your answer is considered correct or helpful by others.

    – Wiktor Stribiżew
    Nov 27 '18 at 11:03















    1














    I think this will solve your problem.



    ^[a-z0-9]+.[a-z0-9]+((.[a-z0-9]+)|*)?$



    Explanation




    ^ - Start of the string.



    [a-z0-9] - any of the character in this range will be valid.



    + - One or more.



    . - Matches literal . (period).



    ((.[a-z0-9]+)|*)? -



        (.[a-z0-9]+) - this sub-group checks for . followed by any digit or characters
    * - matches for asterisk
    ? - make the preceding group optional.


    $ - Anchor to the end of line






    share|improve this answer


























    • It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

      – Code Maniac
      Nov 29 '18 at 4:33













    • Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

      – Pushpesh Kumar Rajwanshi
      Nov 29 '18 at 7:18
















    1














    I think this will solve your problem.



    ^[a-z0-9]+.[a-z0-9]+((.[a-z0-9]+)|*)?$



    Explanation




    ^ - Start of the string.



    [a-z0-9] - any of the character in this range will be valid.



    + - One or more.



    . - Matches literal . (period).



    ((.[a-z0-9]+)|*)? -



        (.[a-z0-9]+) - this sub-group checks for . followed by any digit or characters
    * - matches for asterisk
    ? - make the preceding group optional.


    $ - Anchor to the end of line






    share|improve this answer


























    • It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

      – Code Maniac
      Nov 29 '18 at 4:33













    • Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

      – Pushpesh Kumar Rajwanshi
      Nov 29 '18 at 7:18














    1












    1








    1







    I think this will solve your problem.



    ^[a-z0-9]+.[a-z0-9]+((.[a-z0-9]+)|*)?$



    Explanation




    ^ - Start of the string.



    [a-z0-9] - any of the character in this range will be valid.



    + - One or more.



    . - Matches literal . (period).



    ((.[a-z0-9]+)|*)? -



        (.[a-z0-9]+) - this sub-group checks for . followed by any digit or characters
    * - matches for asterisk
    ? - make the preceding group optional.


    $ - Anchor to the end of line






    share|improve this answer















    I think this will solve your problem.



    ^[a-z0-9]+.[a-z0-9]+((.[a-z0-9]+)|*)?$



    Explanation




    ^ - Start of the string.



    [a-z0-9] - any of the character in this range will be valid.



    + - One or more.



    . - Matches literal . (period).



    ((.[a-z0-9]+)|*)? -



        (.[a-z0-9]+) - this sub-group checks for . followed by any digit or characters
    * - matches for asterisk
    ? - make the preceding group optional.


    $ - Anchor to the end of line







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 29 '18 at 12:56

























    answered Nov 27 '18 at 9:19









    Code ManiacCode Maniac

    7,5201526




    7,5201526













    • It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

      – Code Maniac
      Nov 29 '18 at 4:33













    • Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

      – Pushpesh Kumar Rajwanshi
      Nov 29 '18 at 7:18



















    • It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

      – Code Maniac
      Nov 29 '18 at 4:33













    • Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

      – Pushpesh Kumar Rajwanshi
      Nov 29 '18 at 7:18

















    It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

    – Code Maniac
    Nov 29 '18 at 4:33







    It checks for all the cases what user asked for. let the OP checks and come-up with requirements if it doesn't serve what he asked for. Am i supposed to write a regex which matches every pattern of world ? I think you should read the comments of again Wiktor @PushpeshKumarRajwanshi

    – Code Maniac
    Nov 29 '18 at 4:33















    Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

    – Pushpesh Kumar Rajwanshi
    Nov 29 '18 at 7:18





    Well, OP didn't ask to write a regex that matches every pattern of world as that is trivial which is .* OP was very clear in stating dot separated list and test.test.test is a simple dot separated list which should match. Even Wiktor's or mine answer also matches that simple text but yours doesn't match.

    – Pushpesh Kumar Rajwanshi
    Nov 29 '18 at 7:18











    0














    From your given valid and invalid sample of text, I am concluding following things,




    1. The text will contain word characters.

    2. The word characters can be separated by single dot. Like this abc.xyz or aaa.bbb.ccc

    3. Dot character can't be the first or last character. This is not ok .abc or abc.aaa.

    4. Optionally star (asterisk) character can only appear as the last character. Hence test.text* is fine because test.text is fine but test.text.* is not fine because test.text. is not fine.


    Considering these rules, you can use following regex,



    ^w+(.w+)*(?<!.)[*]?$


    Explanation:





    • ^ --> Start of string


    • w+ --> match a word of one or more length


    • (.w+)* --> Match further word characters zero or more preceded by a single literal dot zero or more times.


    • (?<!.)[*]? --> asterisk character can optionally be present at the end of string which should not be preceded by a literal dot


    • $ --> End of input.


    Demo






    share|improve this answer




























      0














      From your given valid and invalid sample of text, I am concluding following things,




      1. The text will contain word characters.

      2. The word characters can be separated by single dot. Like this abc.xyz or aaa.bbb.ccc

      3. Dot character can't be the first or last character. This is not ok .abc or abc.aaa.

      4. Optionally star (asterisk) character can only appear as the last character. Hence test.text* is fine because test.text is fine but test.text.* is not fine because test.text. is not fine.


      Considering these rules, you can use following regex,



      ^w+(.w+)*(?<!.)[*]?$


      Explanation:





      • ^ --> Start of string


      • w+ --> match a word of one or more length


      • (.w+)* --> Match further word characters zero or more preceded by a single literal dot zero or more times.


      • (?<!.)[*]? --> asterisk character can optionally be present at the end of string which should not be preceded by a literal dot


      • $ --> End of input.


      Demo






      share|improve this answer


























        0












        0








        0







        From your given valid and invalid sample of text, I am concluding following things,




        1. The text will contain word characters.

        2. The word characters can be separated by single dot. Like this abc.xyz or aaa.bbb.ccc

        3. Dot character can't be the first or last character. This is not ok .abc or abc.aaa.

        4. Optionally star (asterisk) character can only appear as the last character. Hence test.text* is fine because test.text is fine but test.text.* is not fine because test.text. is not fine.


        Considering these rules, you can use following regex,



        ^w+(.w+)*(?<!.)[*]?$


        Explanation:





        • ^ --> Start of string


        • w+ --> match a word of one or more length


        • (.w+)* --> Match further word characters zero or more preceded by a single literal dot zero or more times.


        • (?<!.)[*]? --> asterisk character can optionally be present at the end of string which should not be preceded by a literal dot


        • $ --> End of input.


        Demo






        share|improve this answer













        From your given valid and invalid sample of text, I am concluding following things,




        1. The text will contain word characters.

        2. The word characters can be separated by single dot. Like this abc.xyz or aaa.bbb.ccc

        3. Dot character can't be the first or last character. This is not ok .abc or abc.aaa.

        4. Optionally star (asterisk) character can only appear as the last character. Hence test.text* is fine because test.text is fine but test.text.* is not fine because test.text. is not fine.


        Considering these rules, you can use following regex,



        ^w+(.w+)*(?<!.)[*]?$


        Explanation:





        • ^ --> Start of string


        • w+ --> match a word of one or more length


        • (.w+)* --> Match further word characters zero or more preceded by a single literal dot zero or more times.


        • (?<!.)[*]? --> asterisk character can optionally be present at the end of string which should not be preceded by a literal dot


        • $ --> End of input.


        Demo







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 10:39









        Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi

        8,53321027




        8,53321027






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495945%2fregular-expression-to-match-dot-separated-list-with-no-dot-on-the-end-and-allow%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)