Regular expression for a hexadecimal number?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







86















How do I create a regular expression that detects hexadecimal numbers in a text?



For example, ‘0x0f4’, ‘0acdadecf822eeff32aca5830e438cb54aa722e3’, and ‘8BADF00D’.










share|improve this question




















  • 1





    Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

    – Blender
    Feb 10 '12 at 1:10


















86















How do I create a regular expression that detects hexadecimal numbers in a text?



For example, ‘0x0f4’, ‘0acdadecf822eeff32aca5830e438cb54aa722e3’, and ‘8BADF00D’.










share|improve this question




















  • 1





    Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

    – Blender
    Feb 10 '12 at 1:10














86












86








86


8






How do I create a regular expression that detects hexadecimal numbers in a text?



For example, ‘0x0f4’, ‘0acdadecf822eeff32aca5830e438cb54aa722e3’, and ‘8BADF00D’.










share|improve this question
















How do I create a regular expression that detects hexadecimal numbers in a text?



For example, ‘0x0f4’, ‘0acdadecf822eeff32aca5830e438cb54aa722e3’, and ‘8BADF00D’.







regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 15 '16 at 14:07









Peter Mortensen

14k1987114




14k1987114










asked Feb 10 '12 at 1:06









saurcerysaurcery

7401710




7401710








  • 1





    Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

    – Blender
    Feb 10 '12 at 1:10














  • 1





    Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

    – Blender
    Feb 10 '12 at 1:10








1




1





Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

– Blender
Feb 10 '12 at 1:10





Regex doesn't really parse. Try extracting all number-like things and sift out the ones that aren't hexadecimals.

– Blender
Feb 10 '12 at 1:10












9 Answers
9






active

oldest

votes


















151














How about the following?



0[xX][0-9a-fA-F]+


Matches expression starting with a 0, following by either a lower or uppercase x, followed by one or more characters in the ranges 0-9, or a-f, or A-F






share|improve this answer



















  • 27





    That could be shortified to /0x[da-f]/i, but otherwise, +1.

    – Niklas B.
    Feb 10 '12 at 1:13






  • 15





    @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

    – David M. Syzdek
    Feb 10 '12 at 1:39











  • Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

    – saurcery
    Feb 10 '12 at 2:23






  • 2





    '0x[da-f]{2}' propaply better to limit the number too

    – Yazan Rawashdeh
    Apr 11 '16 at 12:54








  • 2





    Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

    – Peter Mortensen
    Aug 11 '16 at 12:34



















35














The exact syntax depends on your exact requirements and programming language, but basically:



/[0-9a-fA-F]+/


or more simply, i makes it case-insensitive.



/[0-9a-f]+/i


If you are lucky enough to be using Ruby, you can do:



/h+/


EDIT - Steven Schroeder's answer made me realise my understanding of the 0x bit was wrong, so I've updated my suggestions accordingly.
If you also want to match 0x, the equivalents are



/0[xX][0-9a-fA-F]+/
/0x[0-9a-f]+/i
/0x[h]+/i


ADDED MORE - If 0x needs to be optional (as the question implies):



/(0x)?[0-9a-f]+/i





share|improve this answer


























  • can you explain me the reason for above RE?

    – saurcery
    Feb 10 '12 at 1:16






  • 3





    @noobDroid What specifically would you like me to explain?

    – SimonMayer
    Feb 10 '12 at 1:19



















15














Not a big deal, but most regex engines support the POSIX character classes, and there's [:xdigit:] for matching hex characters, which is simpler than the common 0-9a-fA-F stuff.



So, the regex as requested (ie. with optional 0x) is: /(0x)?[[:xdigit:]]+/






share|improve this answer































    10














    This will match with or without 0x prefix



    (?:0[xX])?[0-9a-fA-F]+






    share|improve this answer































      9














      It's worth mentioning that detecting an MD5 (which is one of the examples) can be done with:



      [0-9a-fA-F]{32}





      share|improve this answer































        4














        If you're using Perl or PHP, you can replace



        [0-9a-fA-F]


        with:



        [[:xdigit:]]





        share|improve this answer
























        • This ought to be a self-contained answer.

          – Peter Mortensen
          Aug 15 '16 at 14:10



















        3














        Just for the record I would specify the following:



        /^[xX]?[0-9a-fA-F]{6}$/


        Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.






        share|improve this answer

































          1














          If you are looking for an specific hex character in the middle of the string, you can use "xhh" where hh is the character in hexadecimal. I've tried and it works. I use framework for C++ Qt but it can solve problems in other cases, depends on the flavor you need to use (php, javascript, python , golang, etc.).



          This answer was taken from:http://ult-tex.net/info/perl/






          share|improve this answer


























          • Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

            – Maurice
            Jan 2 '17 at 16:07











          • What is "especific anda"?

            – Peter Mortensen
            Sep 25 '17 at 12:19



















          0














          This one makes sure you have no more than three valid pairs:



          (([a-fA-F]|[0-9]){2}){3}


          Any more or less than three pairs of valid characters fail to match.






          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%2f9221362%2fregular-expression-for-a-hexadecimal-number%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            151














            How about the following?



            0[xX][0-9a-fA-F]+


            Matches expression starting with a 0, following by either a lower or uppercase x, followed by one or more characters in the ranges 0-9, or a-f, or A-F






            share|improve this answer



















            • 27





              That could be shortified to /0x[da-f]/i, but otherwise, +1.

              – Niklas B.
              Feb 10 '12 at 1:13






            • 15





              @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

              – David M. Syzdek
              Feb 10 '12 at 1:39











            • Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

              – saurcery
              Feb 10 '12 at 2:23






            • 2





              '0x[da-f]{2}' propaply better to limit the number too

              – Yazan Rawashdeh
              Apr 11 '16 at 12:54








            • 2





              Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

              – Peter Mortensen
              Aug 11 '16 at 12:34
















            151














            How about the following?



            0[xX][0-9a-fA-F]+


            Matches expression starting with a 0, following by either a lower or uppercase x, followed by one or more characters in the ranges 0-9, or a-f, or A-F






            share|improve this answer



















            • 27





              That could be shortified to /0x[da-f]/i, but otherwise, +1.

              – Niklas B.
              Feb 10 '12 at 1:13






            • 15





              @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

              – David M. Syzdek
              Feb 10 '12 at 1:39











            • Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

              – saurcery
              Feb 10 '12 at 2:23






            • 2





              '0x[da-f]{2}' propaply better to limit the number too

              – Yazan Rawashdeh
              Apr 11 '16 at 12:54








            • 2





              Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

              – Peter Mortensen
              Aug 11 '16 at 12:34














            151












            151








            151







            How about the following?



            0[xX][0-9a-fA-F]+


            Matches expression starting with a 0, following by either a lower or uppercase x, followed by one or more characters in the ranges 0-9, or a-f, or A-F






            share|improve this answer













            How about the following?



            0[xX][0-9a-fA-F]+


            Matches expression starting with a 0, following by either a lower or uppercase x, followed by one or more characters in the ranges 0-9, or a-f, or A-F







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 10 '12 at 1:10









            Steven SchroederSteven Schroeder

            3,99611615




            3,99611615








            • 27





              That could be shortified to /0x[da-f]/i, but otherwise, +1.

              – Niklas B.
              Feb 10 '12 at 1:13






            • 15





              @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

              – David M. Syzdek
              Feb 10 '12 at 1:39











            • Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

              – saurcery
              Feb 10 '12 at 2:23






            • 2





              '0x[da-f]{2}' propaply better to limit the number too

              – Yazan Rawashdeh
              Apr 11 '16 at 12:54








            • 2





              Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

              – Peter Mortensen
              Aug 11 '16 at 12:34














            • 27





              That could be shortified to /0x[da-f]/i, but otherwise, +1.

              – Niklas B.
              Feb 10 '12 at 1:13






            • 15





              @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

              – David M. Syzdek
              Feb 10 '12 at 1:39











            • Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

              – saurcery
              Feb 10 '12 at 2:23






            • 2





              '0x[da-f]{2}' propaply better to limit the number too

              – Yazan Rawashdeh
              Apr 11 '16 at 12:54








            • 2





              Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

              – Peter Mortensen
              Aug 11 '16 at 12:34








            27




            27





            That could be shortified to /0x[da-f]/i, but otherwise, +1.

            – Niklas B.
            Feb 10 '12 at 1:13





            That could be shortified to /0x[da-f]/i, but otherwise, +1.

            – Niklas B.
            Feb 10 '12 at 1:13




            15




            15





            @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

            – David M. Syzdek
            Feb 10 '12 at 1:39





            @NiklasB. Your shorthand is only valid if using perl regex, if using POSIX regex, then Steven's solution is the shortest. Either way, Steven's solution works for both perl and POSIX regex.

            – David M. Syzdek
            Feb 10 '12 at 1:39













            Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

            – saurcery
            Feb 10 '12 at 2:23





            Got it! Solution by Steven is good if the hex number starts with 0x or 0X. This one should work better: ^[0-9A-F]+$ It can also recognize hex patterns like: '535GH0G73' For Java, we can use e.g String.matches() for checking this.. Thank you guys for the response :)

            – saurcery
            Feb 10 '12 at 2:23




            2




            2





            '0x[da-f]{2}' propaply better to limit the number too

            – Yazan Rawashdeh
            Apr 11 '16 at 12:54







            '0x[da-f]{2}' propaply better to limit the number too

            – Yazan Rawashdeh
            Apr 11 '16 at 12:54






            2




            2





            Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

            – Peter Mortensen
            Aug 11 '16 at 12:34





            Would that match the second and third example numbers, 0acdadecf822eeff32aca5830e438cb54aa722e3 and 8BADF00D?

            – Peter Mortensen
            Aug 11 '16 at 12:34













            35














            The exact syntax depends on your exact requirements and programming language, but basically:



            /[0-9a-fA-F]+/


            or more simply, i makes it case-insensitive.



            /[0-9a-f]+/i


            If you are lucky enough to be using Ruby, you can do:



            /h+/


            EDIT - Steven Schroeder's answer made me realise my understanding of the 0x bit was wrong, so I've updated my suggestions accordingly.
            If you also want to match 0x, the equivalents are



            /0[xX][0-9a-fA-F]+/
            /0x[0-9a-f]+/i
            /0x[h]+/i


            ADDED MORE - If 0x needs to be optional (as the question implies):



            /(0x)?[0-9a-f]+/i





            share|improve this answer


























            • can you explain me the reason for above RE?

              – saurcery
              Feb 10 '12 at 1:16






            • 3





              @noobDroid What specifically would you like me to explain?

              – SimonMayer
              Feb 10 '12 at 1:19
















            35














            The exact syntax depends on your exact requirements and programming language, but basically:



            /[0-9a-fA-F]+/


            or more simply, i makes it case-insensitive.



            /[0-9a-f]+/i


            If you are lucky enough to be using Ruby, you can do:



            /h+/


            EDIT - Steven Schroeder's answer made me realise my understanding of the 0x bit was wrong, so I've updated my suggestions accordingly.
            If you also want to match 0x, the equivalents are



            /0[xX][0-9a-fA-F]+/
            /0x[0-9a-f]+/i
            /0x[h]+/i


            ADDED MORE - If 0x needs to be optional (as the question implies):



            /(0x)?[0-9a-f]+/i





            share|improve this answer


























            • can you explain me the reason for above RE?

              – saurcery
              Feb 10 '12 at 1:16






            • 3





              @noobDroid What specifically would you like me to explain?

              – SimonMayer
              Feb 10 '12 at 1:19














            35












            35








            35







            The exact syntax depends on your exact requirements and programming language, but basically:



            /[0-9a-fA-F]+/


            or more simply, i makes it case-insensitive.



            /[0-9a-f]+/i


            If you are lucky enough to be using Ruby, you can do:



            /h+/


            EDIT - Steven Schroeder's answer made me realise my understanding of the 0x bit was wrong, so I've updated my suggestions accordingly.
            If you also want to match 0x, the equivalents are



            /0[xX][0-9a-fA-F]+/
            /0x[0-9a-f]+/i
            /0x[h]+/i


            ADDED MORE - If 0x needs to be optional (as the question implies):



            /(0x)?[0-9a-f]+/i





            share|improve this answer















            The exact syntax depends on your exact requirements and programming language, but basically:



            /[0-9a-fA-F]+/


            or more simply, i makes it case-insensitive.



            /[0-9a-f]+/i


            If you are lucky enough to be using Ruby, you can do:



            /h+/


            EDIT - Steven Schroeder's answer made me realise my understanding of the 0x bit was wrong, so I've updated my suggestions accordingly.
            If you also want to match 0x, the equivalents are



            /0[xX][0-9a-fA-F]+/
            /0x[0-9a-f]+/i
            /0x[h]+/i


            ADDED MORE - If 0x needs to be optional (as the question implies):



            /(0x)?[0-9a-f]+/i






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 10 '12 at 1:40

























            answered Feb 10 '12 at 1:11









            SimonMayerSimonMayer

            3,13622335




            3,13622335













            • can you explain me the reason for above RE?

              – saurcery
              Feb 10 '12 at 1:16






            • 3





              @noobDroid What specifically would you like me to explain?

              – SimonMayer
              Feb 10 '12 at 1:19



















            • can you explain me the reason for above RE?

              – saurcery
              Feb 10 '12 at 1:16






            • 3





              @noobDroid What specifically would you like me to explain?

              – SimonMayer
              Feb 10 '12 at 1:19

















            can you explain me the reason for above RE?

            – saurcery
            Feb 10 '12 at 1:16





            can you explain me the reason for above RE?

            – saurcery
            Feb 10 '12 at 1:16




            3




            3





            @noobDroid What specifically would you like me to explain?

            – SimonMayer
            Feb 10 '12 at 1:19





            @noobDroid What specifically would you like me to explain?

            – SimonMayer
            Feb 10 '12 at 1:19











            15














            Not a big deal, but most regex engines support the POSIX character classes, and there's [:xdigit:] for matching hex characters, which is simpler than the common 0-9a-fA-F stuff.



            So, the regex as requested (ie. with optional 0x) is: /(0x)?[[:xdigit:]]+/






            share|improve this answer




























              15














              Not a big deal, but most regex engines support the POSIX character classes, and there's [:xdigit:] for matching hex characters, which is simpler than the common 0-9a-fA-F stuff.



              So, the regex as requested (ie. with optional 0x) is: /(0x)?[[:xdigit:]]+/






              share|improve this answer


























                15












                15








                15







                Not a big deal, but most regex engines support the POSIX character classes, and there's [:xdigit:] for matching hex characters, which is simpler than the common 0-9a-fA-F stuff.



                So, the regex as requested (ie. with optional 0x) is: /(0x)?[[:xdigit:]]+/






                share|improve this answer













                Not a big deal, but most regex engines support the POSIX character classes, and there's [:xdigit:] for matching hex characters, which is simpler than the common 0-9a-fA-F stuff.



                So, the regex as requested (ie. with optional 0x) is: /(0x)?[[:xdigit:]]+/







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 26 '14 at 21:13









                smathysmathy

                20.6k53965




                20.6k53965























                    10














                    This will match with or without 0x prefix



                    (?:0[xX])?[0-9a-fA-F]+






                    share|improve this answer




























                      10














                      This will match with or without 0x prefix



                      (?:0[xX])?[0-9a-fA-F]+






                      share|improve this answer


























                        10












                        10








                        10







                        This will match with or without 0x prefix



                        (?:0[xX])?[0-9a-fA-F]+






                        share|improve this answer













                        This will match with or without 0x prefix



                        (?:0[xX])?[0-9a-fA-F]+







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 1 '13 at 13:35









                        Pawel FurmaniakPawel Furmaniak

                        2,75532232




                        2,75532232























                            9














                            It's worth mentioning that detecting an MD5 (which is one of the examples) can be done with:



                            [0-9a-fA-F]{32}





                            share|improve this answer




























                              9














                              It's worth mentioning that detecting an MD5 (which is one of the examples) can be done with:



                              [0-9a-fA-F]{32}





                              share|improve this answer


























                                9












                                9








                                9







                                It's worth mentioning that detecting an MD5 (which is one of the examples) can be done with:



                                [0-9a-fA-F]{32}





                                share|improve this answer













                                It's worth mentioning that detecting an MD5 (which is one of the examples) can be done with:



                                [0-9a-fA-F]{32}






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Sep 8 '14 at 13:00









                                AdaddinsaneAdaddinsane

                                33349




                                33349























                                    4














                                    If you're using Perl or PHP, you can replace



                                    [0-9a-fA-F]


                                    with:



                                    [[:xdigit:]]





                                    share|improve this answer
























                                    • This ought to be a self-contained answer.

                                      – Peter Mortensen
                                      Aug 15 '16 at 14:10
















                                    4














                                    If you're using Perl or PHP, you can replace



                                    [0-9a-fA-F]


                                    with:



                                    [[:xdigit:]]





                                    share|improve this answer
























                                    • This ought to be a self-contained answer.

                                      – Peter Mortensen
                                      Aug 15 '16 at 14:10














                                    4












                                    4








                                    4







                                    If you're using Perl or PHP, you can replace



                                    [0-9a-fA-F]


                                    with:



                                    [[:xdigit:]]





                                    share|improve this answer













                                    If you're using Perl or PHP, you can replace



                                    [0-9a-fA-F]


                                    with:



                                    [[:xdigit:]]






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 12 '15 at 14:41









                                    joachimjoachim

                                    8,83492936




                                    8,83492936













                                    • This ought to be a self-contained answer.

                                      – Peter Mortensen
                                      Aug 15 '16 at 14:10



















                                    • This ought to be a self-contained answer.

                                      – Peter Mortensen
                                      Aug 15 '16 at 14:10

















                                    This ought to be a self-contained answer.

                                    – Peter Mortensen
                                    Aug 15 '16 at 14:10





                                    This ought to be a self-contained answer.

                                    – Peter Mortensen
                                    Aug 15 '16 at 14:10











                                    3














                                    Just for the record I would specify the following:



                                    /^[xX]?[0-9a-fA-F]{6}$/


                                    Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.






                                    share|improve this answer






























                                      3














                                      Just for the record I would specify the following:



                                      /^[xX]?[0-9a-fA-F]{6}$/


                                      Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.






                                      share|improve this answer




























                                        3












                                        3








                                        3







                                        Just for the record I would specify the following:



                                        /^[xX]?[0-9a-fA-F]{6}$/


                                        Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.






                                        share|improve this answer















                                        Just for the record I would specify the following:



                                        /^[xX]?[0-9a-fA-F]{6}$/


                                        Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 15 '17 at 11:19









                                        Rimian

                                        20.6k994100




                                        20.6k994100










                                        answered Jul 6 '16 at 21:16









                                        batspybatspy

                                        31536




                                        31536























                                            1














                                            If you are looking for an specific hex character in the middle of the string, you can use "xhh" where hh is the character in hexadecimal. I've tried and it works. I use framework for C++ Qt but it can solve problems in other cases, depends on the flavor you need to use (php, javascript, python , golang, etc.).



                                            This answer was taken from:http://ult-tex.net/info/perl/






                                            share|improve this answer


























                                            • Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                              – Maurice
                                              Jan 2 '17 at 16:07











                                            • What is "especific anda"?

                                              – Peter Mortensen
                                              Sep 25 '17 at 12:19
















                                            1














                                            If you are looking for an specific hex character in the middle of the string, you can use "xhh" where hh is the character in hexadecimal. I've tried and it works. I use framework for C++ Qt but it can solve problems in other cases, depends on the flavor you need to use (php, javascript, python , golang, etc.).



                                            This answer was taken from:http://ult-tex.net/info/perl/






                                            share|improve this answer


























                                            • Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                              – Maurice
                                              Jan 2 '17 at 16:07











                                            • What is "especific anda"?

                                              – Peter Mortensen
                                              Sep 25 '17 at 12:19














                                            1












                                            1








                                            1







                                            If you are looking for an specific hex character in the middle of the string, you can use "xhh" where hh is the character in hexadecimal. I've tried and it works. I use framework for C++ Qt but it can solve problems in other cases, depends on the flavor you need to use (php, javascript, python , golang, etc.).



                                            This answer was taken from:http://ult-tex.net/info/perl/






                                            share|improve this answer















                                            If you are looking for an specific hex character in the middle of the string, you can use "xhh" where hh is the character in hexadecimal. I've tried and it works. I use framework for C++ Qt but it can solve problems in other cases, depends on the flavor you need to use (php, javascript, python , golang, etc.).



                                            This answer was taken from:http://ult-tex.net/info/perl/







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Dec 7 '17 at 0:24

























                                            answered Jan 2 '17 at 15:29









                                            Fábio BorgesFábio Borges

                                            113




                                            113













                                            • Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                              – Maurice
                                              Jan 2 '17 at 16:07











                                            • What is "especific anda"?

                                              – Peter Mortensen
                                              Sep 25 '17 at 12:19



















                                            • Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                              – Maurice
                                              Jan 2 '17 at 16:07











                                            • What is "especific anda"?

                                              – Peter Mortensen
                                              Sep 25 '17 at 12:19

















                                            Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                            – Maurice
                                            Jan 2 '17 at 16:07





                                            Hey! While this might be true for perl, it doesn't seem to be the case for Regular Expressions in all programming languages. According to this x is the equivalent to u in other languages.

                                            – Maurice
                                            Jan 2 '17 at 16:07













                                            What is "especific anda"?

                                            – Peter Mortensen
                                            Sep 25 '17 at 12:19





                                            What is "especific anda"?

                                            – Peter Mortensen
                                            Sep 25 '17 at 12:19











                                            0














                                            This one makes sure you have no more than three valid pairs:



                                            (([a-fA-F]|[0-9]){2}){3}


                                            Any more or less than three pairs of valid characters fail to match.






                                            share|improve this answer




























                                              0














                                              This one makes sure you have no more than three valid pairs:



                                              (([a-fA-F]|[0-9]){2}){3}


                                              Any more or less than three pairs of valid characters fail to match.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                This one makes sure you have no more than three valid pairs:



                                                (([a-fA-F]|[0-9]){2}){3}


                                                Any more or less than three pairs of valid characters fail to match.






                                                share|improve this answer













                                                This one makes sure you have no more than three valid pairs:



                                                (([a-fA-F]|[0-9]){2}){3}


                                                Any more or less than three pairs of valid characters fail to match.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Sep 18 '14 at 17:53









                                                Local NeedsLocal Needs

                                                1912318




                                                1912318






























                                                    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%2f9221362%2fregular-expression-for-a-hexadecimal-number%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

                                                    mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                                                    How to change which sound is reproduced for terminal bell?

                                                    Can I use Tabulator js library in my java Spring + Thymeleaf project?