Thread: Regex help
View Single Post
Old Nov 20th, 2007, 6:41 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
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