Regex number and hyphenHow to write a regex for digits separated by - in pythonWhat is the best regular expression to check if a string is a valid URL?Regex for numbers onlyRegular Expression for alphanumeric and underscoresRegular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?How to negate specific word in regex?How to match “anything up until this sequence of characters” in a regular expression?Regex - Should hyphens be escaped?How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Where can I get macOS Catalina Beta version?

Meaning of もてり and use of が

Skipping over failed imports until they are needed (if ever)

Are there any features that help with the roll to avoid the destruction of a Wand of Fireballs when using the last charge?

Does the Pi 4 resolve the Ethernet+USB bottleneck issue of past versions?

Can you sign using a digital signature itself?

Can the passive "être + verbe" sometimes mean the past?

Being paid less than a "junior" colleague

How can a valley surrounded by mountains be fertile and rainy?

Why are there so many religions and gods?

Can the UK Prime Minister immediately withdraw the country from the EU without backing from parliament?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Can a police officer film me on their personal device in my own home?

How can I reduce the sound of rain on a range hood vent?

Reverse of diffraction

What does grep -v "grep" mean and do?

Do space suits measure "methane" levels or other biological gases?

Is it bad to describe a character long after their introduction?

Generate and graph the Recamán Sequence

Can 'leave' mean 'forget'?

Is there a nice way to assign std::minmax(a, b) to std::tie(a, b)?

Question on oracles

3D nonogram, beginner's edition

In the context of a differentiator circuit, what is a “current-sensing resistor”?



Regex number and hyphen


How to write a regex for digits separated by - in pythonWhat is the best regular expression to check if a string is a valid URL?Regex for numbers onlyRegular Expression for alphanumeric and underscoresRegular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?How to negate specific word in regex?How to match “anything up until this sequence of characters” in a regular expression?Regex - Should hyphens be escaped?How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm trying to match number with regular expression like:



34-7878-3523-4233


with this:



^[0-9][0-9-]*-[0-9-]*[0-9]$


But the expression also allow



34--34--------88



So how can I allow only one hyphen between the number?










share|improve this question




























    3















    I'm trying to match number with regular expression like:



    34-7878-3523-4233


    with this:



    ^[0-9][0-9-]*-[0-9-]*[0-9]$


    But the expression also allow



    34--34--------88



    So how can I allow only one hyphen between the number?










    share|improve this question
























      3












      3








      3








      I'm trying to match number with regular expression like:



      34-7878-3523-4233


      with this:



      ^[0-9][0-9-]*-[0-9-]*[0-9]$


      But the expression also allow



      34--34--------88



      So how can I allow only one hyphen between the number?










      share|improve this question














      I'm trying to match number with regular expression like:



      34-7878-3523-4233


      with this:



      ^[0-9][0-9-]*-[0-9-]*[0-9]$


      But the expression also allow



      34--34--------88



      So how can I allow only one hyphen between the number?







      regex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 25 '12 at 13:02









      vusanvusan

      3,7544 gold badges33 silver badges73 bronze badges




      3,7544 gold badges33 silver badges73 bronze badges






















          3 Answers
          3






          active

          oldest

          votes


















          17














          Your regex:



          See it in action: Regexr.com



          ^[0-9]+(-[0-9]+)+$


          Matches:



          1-2
          1-2-3


          Doesn't match:



          1
          1-
          1-2-
          1-2----3
          1---3





          share|improve this answer

























          • Thanks but for me there should exist at least one hyphen

            – vusan
            Dec 25 '12 at 13:09











          • @vusan OK, updated the regex.

            – mmdemirbas
            Dec 25 '12 at 13:10


















          6














          That's because, you have included the hyphen in the allowed characters in your character class. You should have it outside.



          You can try something like this: -



          ^([0-9]+-)*[0-9]+$


          Now this will match 0 or more repetition of some digits followed by a hyphen. Then one or more digits at the end.






          share|improve this answer























          • It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

            – vusan
            Dec 25 '12 at 13:07











          • @vusan. No it will match multiple digit now. I forgot to put quantifiers.

            – Rohit Jain
            Dec 25 '12 at 13:07


















          3














          Use the normal*(special normal*)* pattern:



          ^[0-9]+(-[0-9]+)+$


          where normal is [0-9] and special is -






          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%2f14030873%2fregex-number-and-hyphen%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









            17














            Your regex:



            See it in action: Regexr.com



            ^[0-9]+(-[0-9]+)+$


            Matches:



            1-2
            1-2-3


            Doesn't match:



            1
            1-
            1-2-
            1-2----3
            1---3





            share|improve this answer

























            • Thanks but for me there should exist at least one hyphen

              – vusan
              Dec 25 '12 at 13:09











            • @vusan OK, updated the regex.

              – mmdemirbas
              Dec 25 '12 at 13:10















            17














            Your regex:



            See it in action: Regexr.com



            ^[0-9]+(-[0-9]+)+$


            Matches:



            1-2
            1-2-3


            Doesn't match:



            1
            1-
            1-2-
            1-2----3
            1---3





            share|improve this answer

























            • Thanks but for me there should exist at least one hyphen

              – vusan
              Dec 25 '12 at 13:09











            • @vusan OK, updated the regex.

              – mmdemirbas
              Dec 25 '12 at 13:10













            17












            17








            17







            Your regex:



            See it in action: Regexr.com



            ^[0-9]+(-[0-9]+)+$


            Matches:



            1-2
            1-2-3


            Doesn't match:



            1
            1-
            1-2-
            1-2----3
            1---3





            share|improve this answer















            Your regex:



            See it in action: Regexr.com



            ^[0-9]+(-[0-9]+)+$


            Matches:



            1-2
            1-2-3


            Doesn't match:



            1
            1-
            1-2-
            1-2----3
            1---3






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 25 '12 at 19:12

























            answered Dec 25 '12 at 13:05









            mmdemirbasmmdemirbas

            7,2162 gold badges34 silver badges50 bronze badges




            7,2162 gold badges34 silver badges50 bronze badges












            • Thanks but for me there should exist at least one hyphen

              – vusan
              Dec 25 '12 at 13:09











            • @vusan OK, updated the regex.

              – mmdemirbas
              Dec 25 '12 at 13:10

















            • Thanks but for me there should exist at least one hyphen

              – vusan
              Dec 25 '12 at 13:09











            • @vusan OK, updated the regex.

              – mmdemirbas
              Dec 25 '12 at 13:10
















            Thanks but for me there should exist at least one hyphen

            – vusan
            Dec 25 '12 at 13:09





            Thanks but for me there should exist at least one hyphen

            – vusan
            Dec 25 '12 at 13:09













            @vusan OK, updated the regex.

            – mmdemirbas
            Dec 25 '12 at 13:10





            @vusan OK, updated the regex.

            – mmdemirbas
            Dec 25 '12 at 13:10













            6














            That's because, you have included the hyphen in the allowed characters in your character class. You should have it outside.



            You can try something like this: -



            ^([0-9]+-)*[0-9]+$


            Now this will match 0 or more repetition of some digits followed by a hyphen. Then one or more digits at the end.






            share|improve this answer























            • It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

              – vusan
              Dec 25 '12 at 13:07











            • @vusan. No it will match multiple digit now. I forgot to put quantifiers.

              – Rohit Jain
              Dec 25 '12 at 13:07















            6














            That's because, you have included the hyphen in the allowed characters in your character class. You should have it outside.



            You can try something like this: -



            ^([0-9]+-)*[0-9]+$


            Now this will match 0 or more repetition of some digits followed by a hyphen. Then one or more digits at the end.






            share|improve this answer























            • It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

              – vusan
              Dec 25 '12 at 13:07











            • @vusan. No it will match multiple digit now. I forgot to put quantifiers.

              – Rohit Jain
              Dec 25 '12 at 13:07













            6












            6








            6







            That's because, you have included the hyphen in the allowed characters in your character class. You should have it outside.



            You can try something like this: -



            ^([0-9]+-)*[0-9]+$


            Now this will match 0 or more repetition of some digits followed by a hyphen. Then one or more digits at the end.






            share|improve this answer













            That's because, you have included the hyphen in the allowed characters in your character class. You should have it outside.



            You can try something like this: -



            ^([0-9]+-)*[0-9]+$


            Now this will match 0 or more repetition of some digits followed by a hyphen. Then one or more digits at the end.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 25 '12 at 13:04









            Rohit JainRohit Jain

            172k39 gold badges327 silver badges453 bronze badges




            172k39 gold badges327 silver badges453 bronze badges












            • It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

              – vusan
              Dec 25 '12 at 13:07











            • @vusan. No it will match multiple digit now. I forgot to put quantifiers.

              – Rohit Jain
              Dec 25 '12 at 13:07

















            • It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

              – vusan
              Dec 25 '12 at 13:07











            • @vusan. No it will match multiple digit now. I forgot to put quantifiers.

              – Rohit Jain
              Dec 25 '12 at 13:07
















            It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

            – vusan
            Dec 25 '12 at 13:07





            It just allow with one hyphen with single digit like 3-3-3. I want to match like 232424-42-2455

            – vusan
            Dec 25 '12 at 13:07













            @vusan. No it will match multiple digit now. I forgot to put quantifiers.

            – Rohit Jain
            Dec 25 '12 at 13:07





            @vusan. No it will match multiple digit now. I forgot to put quantifiers.

            – Rohit Jain
            Dec 25 '12 at 13:07











            3














            Use the normal*(special normal*)* pattern:



            ^[0-9]+(-[0-9]+)+$


            where normal is [0-9] and special is -






            share|improve this answer



























              3














              Use the normal*(special normal*)* pattern:



              ^[0-9]+(-[0-9]+)+$


              where normal is [0-9] and special is -






              share|improve this answer

























                3












                3








                3







                Use the normal*(special normal*)* pattern:



                ^[0-9]+(-[0-9]+)+$


                where normal is [0-9] and special is -






                share|improve this answer













                Use the normal*(special normal*)* pattern:



                ^[0-9]+(-[0-9]+)+$


                where normal is [0-9] and special is -







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 25 '12 at 13:05









                fgefge

                93k18 gold badges196 silver badges285 bronze badges




                93k18 gold badges196 silver badges285 bronze badges



























                    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%2f14030873%2fregex-number-and-hyphen%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현