Matching Pure Numeric and '' with Python re

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wijaya Edward

    #1

    Matching Pure Numeric and '' with Python re


    Hi,

    Given this list:

    list = ['0123', '1A34' , '333-' , '' ]

    I want to match only this element
    '0123' (pure numeric) and '' (empty element).

    Why this construct doesn't work?

    p = re.compile("''+ |[0-9]+")
    m = p.match(word)
    if m:
    print word,

    Namely it doesn't print 0123 and ''.
    What's wrong with my regex?

    -- Edward WIJAYA
    SINGAPORE

    ------------ Institute For Infocomm Research - Disclaimer -------------
    This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you.
    --------------------------------------------------------
Working...