View Full Version : regex + python

July 28th, 2009, 10:13 PM
hey i had a quick question about regular expressions in python

this is probably rather "noobie" but regex is not one of my strong points.

say i want to grab all the lines from an input file that do not begin with the character C

i know the expression to grab the lines that do begin with C is


but i cant figure out how to just grab the lines that donot begin with C. is there any sort of negation in regex?

ex. !(^C).* <-- didnt work :(

any ideas?

July 28th, 2009, 10:35 PM

That is suppose to be a capital C, but for some reason VBulletin is not allowing me to write that.

Anyway, [^C] means any character except C.

July 28th, 2009, 10:39 PM

edit: sorry works great thanks! ... kindof

July 28th, 2009, 11:04 PM
edit fixed it

July 29th, 2009, 01:09 AM
simple task like this you don't need regular expression. if its not your strong points, then focus more on Python's basics...

if not mystring.startswith("C") :
print "doesn't start with c"