Regular expression to match a #

Tom Deco t.deconinck at gmail.com
Thu Aug 11 06:35:02 EDT 2005


Hi,

I'm trying to use a regular expression to match a string containing a #
(basically i'm looking for #include ...)

I don't seem to manage to write a regular expression that matches this.

My (probably to naive) approach is: p = re.compile(r'\b#include\b)
I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use
a backslash as escape character before the #
None of the above return a match for a string like "#include <stdio>".

I know a # is used for comments, hence my attempt to escape it...

Any suggestion on how to get a regular expression to find a #?

Thanks




More information about the Python-list mailing list