Regular Expressions

Discussion in 'Python' started by Oriana, Aug 27, 2004.

  1. Oriana

    Oriana Guest

    hi!

    I am trying to do some replacements using regular expressions, but
    I'm not exactly sure how to do it. I need to replace all ocurrences of

    /****************************************** OR
    /*

    for /** ....meaning, any / (forward slash) followed by one or more
    asterisks needs to be replaced with /** ....how would I write a pieco
    of code to do this?? Please help! Thanks in advance...

    Ori
     
    Oriana, Aug 27, 2004
    #1
    1. Advertising

  2. On 2004-08-27, Oriana <> wrote:
    > hi!
    >
    > I am trying to do some replacements using regular expressions, but
    > I'm not exactly sure how to do it. I need to replace all ocurrences of
    >
    > /****************************************** OR
    > /*
    >
    > for /** ....meaning, any / (forward slash) followed by one or more
    > asterisks needs to be replaced with /** ....how would I write a pieco
    > of code to do this?? Please help! Thanks in advance...


    #first create a regular expression object.
    foo = re.compile(r"^/\*+")

    #The regular expression here means match any pattern at the start
    #of a line (^) followed by a literal asterisk (\*) repeated one or
    #more times (+).

    #then use the re object to do the substitution magic. I find the
    #syntax for re.sub() to be a bit backwards myself. It might help to
    #think of it as "put the replacement into the line."

    newline = foo.sub("/**",line)



    >
    > Ori



    --
    Kirk Job-Sluder
    "The square-jawed homunculi of Tommy Hilfinger ads make every day an
    existential holocaust." --Scary Go Round
     
    Kirk Job-Sluder, Aug 27, 2004
    #2
    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. Jay Douglas

    Custom Regular Expressions in ASP.net

    Jay Douglas, Nov 2, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    609
    mikeb
    Nov 3, 2003
  2. mark

    Regular expressions

    mark, Jun 30, 2003, in forum: Perl
    Replies:
    4
    Views:
    1,725
  3. Dustin D.
    Replies:
    1
    Views:
    11,227
  4. Jay Douglas
    Replies:
    0
    Views:
    610
    Jay Douglas
    Aug 15, 2003
  5. Noman Shapiro
    Replies:
    0
    Views:
    235
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page