Loading ...
Sorry, an error occurred while loading the content.

494RE: [NTS] Trying to perfect RegExp to match various numbers

Expand Messages
  • John Shotsky
    Mar 29, 2011
      After reading through this several times, I could not determine the actual goal. To get good assistance, you should
      provide the starting data, the result that is wanted, and the rules you want, as well as identifying any data you don't
      want.

      So, is the goal to sort? By numbers only? Padded numbers? Or is the actual data not of interest in your message? It
      seems that the first part of the message and the last part are not on the same subject to me.

      Regards,
      John


      From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of mycroftj
      Sent: Monday, March 28, 2011 16:10
      To: ntb-scripts@yahoogroups.com
      Subject: [NTS] Trying to perfect RegExp to match various numbers


      My ultimate goal was to create a script that (left) space or zero pads numbers to a fixed length for sorting.

      Actual data looks something like

      File 67817 Id.ppt
      File 691037 20dat.sys
      File 69870 Lock.doc
      File 705 56968.mbs
      File 70537 Jil.xls
      File 71168 Gas.jpg

      I then became interested in trying to find a regexp that will match numbers surrounded by BOL, EOL, spaces and tabs with
      signs, decimal point and commas optional.

      In the following test data. the numbers starting with 123 should be matched as well as the integers 0, 1 and 2.
      xxx456 and 456xx should NOT be matched.

      I have something that mostly works but it also matches x456 and the t2 in hmt2. WHY IS THAT?
      It also misses 0, 1 and 2 although it does (correctly) pick up -2.

      I put in the caret because it was not matching numbers at the start of a line. Is that how it's done?

      Thanks for your help. I ordered the Regular Expressions Cookbook today. Hope it's as good as the reviews say!

      Joy

      What I have so far [^\s][\-\+]?\d+,*\d*\.?\d*(?=\s)


      12345
      12345.678
      1234567.90
      xxx456
      456xx

      xx456,123.34
      www.45.67.hmt2

      12,345
      -12,345
      12,345.
      +12,345.01

      12345
      +123,45.678
      1234567.90

      there are 0 lines
      1 or 2 more.

      12345
      -12345.678
      1234567.90
      xxx456
      +456xx

      xx456.34
      www.45.67.hmt2

      +12345

      12345
      -12345.678
      1234567.90
      xxx456
      456xx

      there are 0 lines. The zero should match as should the following one and negative two.
      1 or -2 more.



      [Non-text portions of this message have been removed]
    • Show all 14 messages in this topic