Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 20th, 2007, 3:03 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Regex help

Hi all,

I need some help with a regular expression. I need to match entire Python functions; so, beginning with "(\W+)def .*(.*):" I need to math the following line, assuming it begins with more whitespace the first line, and any following lines that begin with the same amount of whitespace as that line. I am not worried about one-liners and other details right now, just what I described.

Please help! I'm not even sure this is possible, but I hope it is.
titaniumdecoy is offline   Reply With Quote
Old Nov 20th, 2007, 6:41 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Re: Regex help

Try something like:
r"^\W*def .*\(.*\):.*\n(\W+).*(\n\1.*)*"
Notes:
  1. I used \r so the backslashes don't mean escape. I don't
  2. Changed the + to a * after the first \W so you can have "def" starting at the start of the line
  3. Changed the ( to \( so that it actually matched the bracket in the source rather than being a collecting group
  4. I used a collecting group (\W+) to collect the first lot of leading spaces
  5. \1 matches the white space collected in the first group above
Hope this helps - It seemed to work for me, but I didn't try it out extensively.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RegEx problem.. cyphix PHP 4 Mar 4th, 2007 6:24 AM
Email validating regex Jimbo PHP 6 Jul 6th, 2006 2:58 PM
regex (preg_replace) parsing para PHP 2 Dec 31st, 2005 6:30 PM
Regex help Simon Gray PHP 10 Sep 7th, 2005 11:02 AM
Need quick help with regex EyeLezz C# 0 May 16th, 2005 7:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC