simple RE?. if u answer, then i donate $1 to ...
BA
asdffdsa at bellatlantic.net
Mon May 14 10:03:38 EDT 2001
hello and thanks for reading this.
if you can answer this simple question i will put $1 into the poor kids fund
at my local quickcheck grocery store
i am new to python and re but a long time vb programmer.
i see the amazing potential power in re but it is a bit confusing.
i own two python books and i am still a litttle confused???
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
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"
the following are examples of strings that should fail the match. the
failure is based on the fact the single quote must not precede the Option
Explict string. i do not care about white space before or after the first
single quote. after the Option Explict there must be a space or end-of-line
terminator.
line_oe_nok1="'Option Explicit 'hello"
line_oe_nok2="' Option Explicit 'hello"
line_oe_nok3=" 'Option Explicit 'hello"
line_oe_nok4=" ' Option Explicit 'hello"
line_oe_nok5=" ' Option Explicitz 'hello"
line_oe_nok6=" ' Option Explicitz 'hello"
the following are strings that should pass the match:
line_oe_ok1=" Option Explicit 'hello"
line_oe_ok2="Option Explicit "
line_oe_ok2="Option Explicit"
the following are a couple of the many patterns i have tried:
pat_oe_ok1=r"^[^']\s*Option Explicit" #ok: Option Explict
pat_oe_ok2=r"^\s*[^']\s*Option Explicit" #ok: Option Explict
the re pattern i am using will only matcth
line_oe_ok1
and will fail to match
line_oe_ok2
the code line is:
topline=line_oe_ok2
m=re.search(pat,topline)
if m:
return 1
else:
return 0
what am i doing wrong?
thanks,
dave
More information about the Python-list
mailing list