simple RE?. if u answer, then i donate $1 to ...
Alex Martelli
aleaxit at yahoo.com
Mon May 14 10:57:01 EDT 2001
"BA" <asdffdsa at bellatlantic.net> wrote in message
news:_ARL6.48740$Rg2.2296604 at typhoon2.ba-dsg.net...
[snip]
> the concept is that i do not care if there is leading white space or not.
i
> do care that the first non-white space character is NOT a single quote. i
am
So your RE is x=r"\s*[^']", right? re.match(x,astring) will match
astring if it does contain a non-' character as the first non-ws one.
You only need to start the RE string itself with ^ if you plan to
call re.search -- re.match is anchored at the beginning anyway (it
may be different if you're trying to search multiple lines at once).
> trying to write a simple parser for m$-visual basic source code and a
> leading single quote means a comment.
> if you know of a python based parser for vb code, please let me know.
> anyhoo,
>
> the following are the patterns i have tried:
> pat_oe_ok1=r"^[^']\s*Option Explicit"
> pat_oe_ok2=r"^\s*[^']\s*Option Explicit"
This is more specific, it would be matched by r'\s*Option Explicit',
and you'll also need to pass the re.I option to re.match to tell it
to do the matching in a case-insensitive way (else lowercase and
uppercase are not considered identical).
Alex
More information about the Python-list
mailing list