Locked what is wrong with this regex

  • Friday, June 01, 2012 7:25 AM
     
      Has Code

    the regex is

    (?<stkSymbol>[a-z][-a-z0-9.]{0,32})
    \s(?<qty>[-0-9]{1,8}([.]\d{1,4}){0,1})

    with IgnoreCase,Explict capture, IgnoreWhiteSpace

    capture groups ${stkSymbol},${qty}

    a sample data from whic the above fails to extract is the symbol C102423:

    ADBE 276 32.228 8,894.92 5,118.28 +3,776.64 
    C102423  200 0.00 0.00 1,199.00 -1,199.00   
    CP 250 75.08 18,770.00 7,952.84 +10,817.16 
    GIB.A 300 20.97 6,291.00 3,449.00 +2,842.00

    The result contains only 3 instead of 4 rows:

    ADBE	276
    CP	250
    GIB.A	300

    What can I do to fix the regex for stkSymbol?

    BTW: the complete regex has a lot more capture groups but the simplied version illuatrates the problem quickly

All Replies

  • Friday, June 01, 2012 10:50 AM
     
     

    you forgot a plus there:

    (?<stkSymbol>[a-z][-a-z0-9.]{0,32})
    \s+(?<qty>[-0-9]{1,8}([.]\d{1,4}){0,1})

    This means you can get more than one white space between the two first words:


    • Edited by FlashCube Friday, June 01, 2012 10:53 AM
    •  
  • Friday, June 01, 2012 10:54 AM
     
     Answered
    On Fri, 1 Jun 2012 07:25:41 +0000, fs - ab wrote:
     
    >
    >
    >the regex is (?<stkSymbol>[a-z][-a-z0-9.]{0,32})
    >\s(?<qty>[-0-9]{1,8}([.]\d{1,4}){0,1})
    >
    >with IgnoreCase,Explict capture, IgnoreWhiteSpace
    >
    >capture groups ${stkSymbol},${qty}
    >
    >a sample data from whic the above fails to extract is the symbol C102423: ADBE 276 32.228 8,894.92 5,118.28 +3,776.64 
    >C102423  200 0.00 0.00 1,199.00 -1,199.00   
    >CP 250 75.08 18,770.00 7,952.84 +10,817.16 
    >GIB.A 300 20.97 6,291.00 3,449.00 +2,842.00
    >
    >The result contains only 3 instead of 4 rows:
    >ADBE    276
    >CP      250
    >GIB.A   300
    >
    >What can I do to fix the regex for stkSymbol?
    >
    >BTW: the complete regex has a lot more capture groups but the simplied version illuatrates the problem quickly
     
    The problem seems to be that there are two spaces after C102423 and your regex only allows for a single space.
     
    Try:
     
    (?<stkSymbol>[a-z][-a-z0-9.]{0,32})
    \s+(?<qty>[-0-9]{1,8}([.]\d{1,4}){0,1})
     
     

    Ron
    • Marked As Answer by fs - ab Friday, June 01, 2012 5:04 PM
    •  
  • Friday, June 01, 2012 5:07 PM
     
     
    ths to everyone. I missed the extra space after that odd line of C102423