Re: RE module question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    Re: RE module question

    En Fri, 03 Oct 2008 03:59:18 -0300, aditya shukla
    <adityashukla19 83@gmail.comesc ribió:
    Hello folks :
    >
    i have a string "-bin-ulockmgr_server :0.99[&&NHX:C=0.19 5.0]" from which i
    want to delete [&&NHX:C=0.19 5.0] .
    I wrote a regular expression for [&&NHX:C=0.19 5.0] as
    \[&&(\w)+:\w=( (-)?(\d|\d\d|\d\d \d)\.)+\d\]
    >
    now when i do
    >
    p = re.compile('\[&&(\w)+:\w=( (-)?(\d|\d\d|\d\d \d)\.)+\d\]')
    m =p.search("-bin-ulockmgr_server :0.99[&&NHX:C=0.19 5.0]")
    print m
    <_sre.SRE_Mat ch object at 0x01314EE8>
    >>>print m.group()
    [&&NHX:C=0.19 5.0]
    >
    So i guess i am able to find the substring , my question is how can i
    delete
    this substring from the original string? ie
    -bin-ulockmgr_server :0.99 should be my output.
    Instead of p.search, use p.sub
    Or, if you need the match for other purposes, delete the characters from
    m.start() to m.end()

    See http://docs.python.org/library/re.ht...ession-objects

    --
    Gabriel Genellina

Working...