String Manipulation Help!

Dave davidworley at gmail.com
Sat Jan 28 15:57:33 EST 2006


OK, I'm stumped.

I'm trying to find newline characters (\n, specifically) that are NOT
in comments.

So, for example (where "<-" = a newline character):
==========================================
1: <-
2: /*<-
3: ----------------------<-
4:     comment<-
5: ----------------------<-
6: */<-
7: <-
8: CODE CODE CODE<-
9: <-
==========================================

I want to return the newline characters at lines 1, 6, 7, 8, and 9 but
NOT the others.

I've tried using regular expressions but I dislike them because they
aren't immediately readable (and also I don't bloody understand the
things). I'm not opposed to using them, though, if they provide a
solution to this problem!

Thanks in advance for any suggestions anyone can provide.

- Dave




More information about the Python-list mailing list