4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by bvdet
0

You can use the string module and the find() function (read all about it in the python reference ):
http://docs.python.org/lib/node42.html

line.find('text_I_want_to_find')

will normally give you the index of the found pattern, or else -1....I mostly use it to test the existence when parsing with "if line.find('blabla') !=-1:" then I haven't found that blabla pattern and I do certain things....

Helpful?

0

You can use the split() method.
substrs=line.split()
if (substrs[0]=="call") and (substrs[1].startswith("%"):
You will probably have to check for a length of 2 or more and may want to convert to lower case before comparing to "call", but that is the general idea.

0

The other solutions offered work fine. If you want to use a regular expression, the following may work also:

import re
patt = re.compile(r'call +(?!%\S+%)')

print patt.match('call %_junk% text1')
print patt.match('call GetFiles %Label%')

This matches the word 'call' at the beginning of the line followed by any number of spaces if not followed by a series on non-whitespace characters preceded and followed by the character '%'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.