text search again??????????
John Hunter
jdhunter at nitace.bsd.uchicago.edu
Sat Jun 22 10:03:03 EDT 2002
>>>>> "jubafre" == jubafre <jubafre at zipmail.com.br> writes:
jubafre> self.text.search(st, 0.0, regexp='true') is it correct???
jubafre> i´m not a exact string, i´m searchin for winzip, but in
jubafre> the text appears WinZip and the search doesn´t work, how
jubafre> use regexp flag?????
What kind of object is self.text? You say, 'I'm not a exact
string'. I'm not either, but this confuses me in the context of your
question.
My guess is that self.text is a string, and you'll be fine with the
string 'find' method. You don't need a regex to search for 'winzip'.
self.text.lower().find('winzip') will do a case insensitive search for
winzip and return the index into the string, or '-1' if nothing is
found. self.text.find('WinZip') will do a case sensitive search.
If self.text is a rgx object, then you could use it's search method,
but the syntax would be:
self.text = re.compile('WinZip') # see the docs for case insensitive
self.text.search(s) # s is the string you want to search.
But if this is the case, text would be a bad name.
self.rgxWinzip would be better than self.text.
Good luck,
John Hunter
The re search method:
`search(string[, pos[, endpos]])'
Scan through STRING looking for a location where this regular
expression produces a match, and return a corresponding
`MatchObject' instance. Return `None' if no position in the
string matches the pattern; note that this is different from
finding a zero-length match at some point in the string.
The optional POS and ENDPOS parameters have the same meaning as
for the `match()' method.
The string find method:
`find(s, sub[, start[,end]])'
Return the lowest index in S where the substring SUB is found such
that SUB is wholly contained in `S[START:END]'. Return `-1' on
failure. Defaults for START and END and interpretation of
negative values is the same as for slices.
More information about the Python-list
mailing list