RE: + in regular expression

Discussion in 'Python' started by Saroo Jain, Oct 5, 2012.

  1. Saroo Jain

    Saroo Jain Guest

    x3=re.match("\s{6}+",str)

    instead use
    x3=re.match("\s{6,}",str)

    This serves the purpose. And also give some food for thought for why the first one throws an error.

    Cheers,
    Saroo

    -----Original Message-----
    From: Python-list [mailto:python-list-bounces+saroo_jain=] On Behalf Of Mark Lawrence
    Sent: Friday, October 05, 2012 3:29 AM
    To:
    Subject: Re: + in regular expression

    On 04/10/2012 04:01, contro opinion wrote:
    >>>> str=" gg"
    >>>> x1=re.match("\s+",str)
    >>>> x1

    > <_sre.SRE_Match object at 0xb7354db0>
    >>>> x2=re.match("\s{6}",str)
    >>>> x2

    > <_sre.SRE_Match object at 0xb7337f38>
    >>>> x3=re.match("\s{6}+",str)

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > File "/usr/lib/python2.6/re.py", line 137, in match
    > return _compile(pattern, flags).match(string)
    > File "/usr/lib/python2.6/re.py", line 245, in _compile
    > raise error, v # invalid expression
    > sre_constants.error: multiple repeat
    >>>>

    >
    > why the "\s{6}+" is not a regular pattern?
    >
    >
    >


    Why are you too lazy to do any research before posting a question?

    --
    Cheers.

    Mark Lawrence.

    --
    http://mail.python.org/mailman/listinfo/python-list

    **************** CAUTION - Disclaimer *****************
    This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
    for the use of the addressee(s). If you are not the intended recipient, please
    notify the sender by e-mail and delete the original message. Further, youare not
    to copy, disclose, or distribute this e-mail or its contents to any otherperson and
    any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
    every reasonable precaution to minimize this risk, but is not liable for any damage
    you may sustain as a result of any virus in this e-mail. You should carryout your
    own virus checks before opening the e-mail or attachment. Infosys reserves the
    right to monitor and review the content of all messages sent to or from this e-mail
    address. Messages sent to or from this e-mail address may be stored on the
    Infosys e-mail system.
    ***INFOSYS******** End of Disclaimer ********INFOSYS***
    Saroo Jain, Oct 5, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith-Earl
    Replies:
    1
    Views:
    441
    Mary Chipman
    Jun 15, 2004
  2. VSK
    Replies:
    2
    Views:
    2,272
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    831
    Alan Moore
    Dec 2, 2005
  4. GIMME
    Replies:
    3
    Views:
    11,923
    vforvikash
    Dec 29, 2008
  5. Noman Shapiro
    Replies:
    0
    Views:
    220
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page