Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Regular Expressions

Reply
Thread Tools

Regular Expressions

 
 
Oriana
Guest
Posts: n/a
 
      08-27-2004
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
 
Reply With Quote
 
 
 
 
Kirk Job-Sluder
Guest
Posts: n/a
 
      08-27-2004
On 2004-08-27, Oriana <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Regular Expressions in ASP.net Jay Douglas ASP .Net 3 11-03-2003 08:09 PM
Regular expressions mark Perl 4 10-28-2003 12:37 PM
perl regular expressions return last matched occurence? Dustin D. Perl 1 08-28-2003 01:51 AM
matching curly braces and regular expressions Dustin D. Perl 0 08-26-2003 11:18 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments