Regex: find numbers greater than specific value (with varying decimal lengths)How do I return multiple values from a function?Peak detection in a 2D arrayRegex to replace everything except numbers and a decimal pointRegex greater than zero with 2 decimal placesReplace all elements of Python NumPy Array that are greater than some valueDecimal validation for greater than zeroMatching numbers greater than 40Regex expression to match equal or greater than 1, by increments of .5Use less than or greater than in where clause with a regex in railsRegex matching numbers greater than a decimal value

Scaling arrows.meta with tranform shape

What is the purpose of Strength, Intelligence and Dexterity in Path of Exile?

What does なんだって mean in this case? 「そういう子なんだってだけで...」

Is this position a forced win for Black after move 14?

Can two aircraft stay on the same runway at the same time?

Why is there no Disney logo in MCU movies?

Why did Starhopper's exhaust plume become brighter just before landing?

Generic Extension Method To Count Descendants

How do I portray irrational anger in first person?

How can weighted averages be calculated for a Dataset summarized with GroupBy

How did medieval manors handle population growth? Was there room for more fields to be ploughed?

Pen test results for web application include a file from a forbidden directory that is not even used or referenced

Why is there not a willingness from the world to step in between Pakistan and India?

Defending Castle from Zombies

How can I fix cracks between the bathtub and the wall surround?

How could a self contained organic body propel itself in space

What caused the end of cybernetic implants?

I feel cheated by my new employer, does this sound right?

Do multi-engine jets need all engines with equal age to reduce asymmetry in thrust and fuel consumption arising out of deterioration?

Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?

Why do IR remotes influence AM radios?

Why haven't the British protested Brexit as ardently like Hong Kongers protest?

How do you say "half the time …, the other half …" in German?

What is Soda Fountain Etiquette?



Regex: find numbers greater than specific value (with varying decimal lengths)


How do I return multiple values from a function?Peak detection in a 2D arrayRegex to replace everything except numbers and a decimal pointRegex greater than zero with 2 decimal placesReplace all elements of Python NumPy Array that are greater than some valueDecimal validation for greater than zeroMatching numbers greater than 40Regex expression to match equal or greater than 1, by increments of .5Use less than or greater than in where clause with a regex in railsRegex matching numbers greater than a decimal value






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








3















I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.



My current code works somewhat but is unwieldy - any advice much appreciated:



^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$


Thank you.










share|improve this question



















  • 1





    I see your regex the same as ^0?.[0-9][3-9]d9,11$

    – revo
    Mar 27 at 22:12

















3















I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.



My current code works somewhat but is unwieldy - any advice much appreciated:



^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$


Thank you.










share|improve this question



















  • 1





    I see your regex the same as ^0?.[0-9][3-9]d9,11$

    – revo
    Mar 27 at 22:12













3












3








3








I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.



My current code works somewhat but is unwieldy - any advice much appreciated:



^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$


Thank you.










share|improve this question














I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.



My current code works somewhat but is unwieldy - any advice much appreciated:



^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$


Thank you.







python regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 22:05









user3682157user3682157

5032 gold badges19 silver badges38 bronze badges




5032 gold badges19 silver badges38 bronze badges










  • 1





    I see your regex the same as ^0?.[0-9][3-9]d9,11$

    – revo
    Mar 27 at 22:12












  • 1





    I see your regex the same as ^0?.[0-9][3-9]d9,11$

    – revo
    Mar 27 at 22:12







1




1





I see your regex the same as ^0?.[0-9][3-9]d9,11$

– revo
Mar 27 at 22:12





I see your regex the same as ^0?.[0-9][3-9]d9,11$

– revo
Mar 27 at 22:12












3 Answers
3






active

oldest

votes


















1















You can use an asterisk to denote zero or more of a digit:



^(?:0?.d[3-9]d*)$


This has the added benefit of matching exactly 0.03 or something with (say) 100 decimal places.



If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:



^(?:0?.d[3-9]d9,15)$


Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.






share|improve this answer

























  • thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

    – user3682157
    Mar 27 at 22:23











  • Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

    – ggorlen
    Mar 27 at 22:25



















0















You should simply parse your data as float:



From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$" so essentially you have:



t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""


Simply split into lines and check each line as float



# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)


Output:



Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad





share|improve this answer
































    0















    Here you go: 0.030000000 - 0.999999999999999



    Greater than or equal to .03 and less than 1.0

    at 9-15 decimal places



    0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)


    Expanded



     # 0.030000000 - 0.999999999999999
    0?
    .
    (?:
    03 d7,13
    | 0 [4-9] d7,13
    | [1-9] d8,14
    )


    Note - this was machine generated, there could be some overlap.

    Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)






    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%2f55387195%2fregex-find-numbers-greater-than-specific-value-with-varying-decimal-lengths%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 can use an asterisk to denote zero or more of a digit:



      ^(?:0?.d[3-9]d*)$


      This has the added benefit of matching exactly 0.03 or something with (say) 100 decimal places.



      If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:



      ^(?:0?.d[3-9]d9,15)$


      Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.






      share|improve this answer

























      • thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

        – user3682157
        Mar 27 at 22:23











      • Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

        – ggorlen
        Mar 27 at 22:25
















      1















      You can use an asterisk to denote zero or more of a digit:



      ^(?:0?.d[3-9]d*)$


      This has the added benefit of matching exactly 0.03 or something with (say) 100 decimal places.



      If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:



      ^(?:0?.d[3-9]d9,15)$


      Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.






      share|improve this answer

























      • thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

        – user3682157
        Mar 27 at 22:23











      • Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

        – ggorlen
        Mar 27 at 22:25














      1














      1










      1









      You can use an asterisk to denote zero or more of a digit:



      ^(?:0?.d[3-9]d*)$


      This has the added benefit of matching exactly 0.03 or something with (say) 100 decimal places.



      If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:



      ^(?:0?.d[3-9]d9,15)$


      Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.






      share|improve this answer













      You can use an asterisk to denote zero or more of a digit:



      ^(?:0?.d[3-9]d*)$


      This has the added benefit of matching exactly 0.03 or something with (say) 100 decimal places.



      If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:



      ^(?:0?.d[3-9]d9,15)$


      Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 27 at 22:15









      ggorlenggorlen

      11.8k4 gold badges13 silver badges30 bronze badges




      11.8k4 gold badges13 silver badges30 bronze badges















      • thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

        – user3682157
        Mar 27 at 22:23











      • Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

        – ggorlen
        Mar 27 at 22:25


















      • thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

        – user3682157
        Mar 27 at 22:23











      • Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

        – ggorlen
        Mar 27 at 22:25

















      thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

      – user3682157
      Mar 27 at 22:23





      thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?

      – user3682157
      Mar 27 at 22:23













      Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

      – ggorlen
      Mar 27 at 22:25






      Because .d[3-9] is not optional, so it won't match 0.1 because that string fails the [3-9] character.

      – ggorlen
      Mar 27 at 22:25














      0















      You should simply parse your data as float:



      From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$" so essentially you have:



      t = """0.0000002
      0.4
      0.04
      0.004
      24544.23354
      Also Bad"""


      Simply split into lines and check each line as float



      # splits the string into a list of lines
      for line in (x.strip() for x in t.split("n")):
      try:
      if float(line) >= 0.03:
      print(line)
      else:
      print("Not ok:",line)
      except:
      print("Not ok:",line)


      Output:



      Not ok: 0.0000002
      0.4
      0.04
      Not ok: 0.004
      24544.23354
      Not ok: Also Bad





      share|improve this answer





























        0















        You should simply parse your data as float:



        From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$" so essentially you have:



        t = """0.0000002
        0.4
        0.04
        0.004
        24544.23354
        Also Bad"""


        Simply split into lines and check each line as float



        # splits the string into a list of lines
        for line in (x.strip() for x in t.split("n")):
        try:
        if float(line) >= 0.03:
        print(line)
        else:
        print("Not ok:",line)
        except:
        print("Not ok:",line)


        Output:



        Not ok: 0.0000002
        0.4
        0.04
        Not ok: 0.004
        24544.23354
        Not ok: Also Bad





        share|improve this answer



























          0














          0










          0









          You should simply parse your data as float:



          From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$" so essentially you have:



          t = """0.0000002
          0.4
          0.04
          0.004
          24544.23354
          Also Bad"""


          Simply split into lines and check each line as float



          # splits the string into a list of lines
          for line in (x.strip() for x in t.split("n")):
          try:
          if float(line) >= 0.03:
          print(line)
          else:
          print("Not ok:",line)
          except:
          print("Not ok:",line)


          Output:



          Not ok: 0.0000002
          0.4
          0.04
          Not ok: 0.004
          24544.23354
          Not ok: Also Bad





          share|improve this answer













          You should simply parse your data as float:



          From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$" so essentially you have:



          t = """0.0000002
          0.4
          0.04
          0.004
          24544.23354
          Also Bad"""


          Simply split into lines and check each line as float



          # splits the string into a list of lines
          for line in (x.strip() for x in t.split("n")):
          try:
          if float(line) >= 0.03:
          print(line)
          else:
          print("Not ok:",line)
          except:
          print("Not ok:",line)


          Output:



          Not ok: 0.0000002
          0.4
          0.04
          Not ok: 0.004
          24544.23354
          Not ok: Also Bad






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 22:17









          Patrick ArtnerPatrick Artner

          29.7k6 gold badges26 silver badges45 bronze badges




          29.7k6 gold badges26 silver badges45 bronze badges
























              0















              Here you go: 0.030000000 - 0.999999999999999



              Greater than or equal to .03 and less than 1.0

              at 9-15 decimal places



              0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)


              Expanded



               # 0.030000000 - 0.999999999999999
              0?
              .
              (?:
              03 d7,13
              | 0 [4-9] d7,13
              | [1-9] d8,14
              )


              Note - this was machine generated, there could be some overlap.

              Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)






              share|improve this answer































                0















                Here you go: 0.030000000 - 0.999999999999999



                Greater than or equal to .03 and less than 1.0

                at 9-15 decimal places



                0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)


                Expanded



                 # 0.030000000 - 0.999999999999999
                0?
                .
                (?:
                03 d7,13
                | 0 [4-9] d7,13
                | [1-9] d8,14
                )


                Note - this was machine generated, there could be some overlap.

                Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)






                share|improve this answer





























                  0














                  0










                  0









                  Here you go: 0.030000000 - 0.999999999999999



                  Greater than or equal to .03 and less than 1.0

                  at 9-15 decimal places



                  0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)


                  Expanded



                   # 0.030000000 - 0.999999999999999
                  0?
                  .
                  (?:
                  03 d7,13
                  | 0 [4-9] d7,13
                  | [1-9] d8,14
                  )


                  Note - this was machine generated, there could be some overlap.

                  Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)






                  share|improve this answer















                  Here you go: 0.030000000 - 0.999999999999999



                  Greater than or equal to .03 and less than 1.0

                  at 9-15 decimal places



                  0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)


                  Expanded



                   # 0.030000000 - 0.999999999999999
                  0?
                  .
                  (?:
                  03 d7,13
                  | 0 [4-9] d7,13
                  | [1-9] d8,14
                  )


                  Note - this was machine generated, there could be some overlap.

                  Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 27 at 23:44

























                  answered Mar 27 at 23:38









                  slnsln

                  31.3k3 gold badges17 silver badges45 bronze badges




                  31.3k3 gold badges17 silver badges45 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%2f55387195%2fregex-find-numbers-greater-than-specific-value-with-varying-decimal-lengths%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

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript