/[cvs]/joko/TestArea/python/regex.py
ViewVC logotype

Contents of /joko/TestArea/python/regex.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Mon Jan 20 18:24:53 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-python
+ initial check-in

1 import string
2 import re
3
4 content=" \
5 function abc(abc, def) { \n\
6 blah blah \n\
7 } \n\
8 function huhu(abc, def) { \n\
9 blah blah \n\
10 } \n\
11 sub def(abc, def) { \n\
12 blah blah \n\
13 } \n\
14 function blah(abc, def) { \n\
15 blah blah \n\
16 } \n\
17 "
18
19
20 # ---------------------------------------------------------
21
22 sigpart = '(.+?)[\(| ]'
23 regex_func=re.compile('function ' + sigpart)
24 regex_sub=re.compile('sub ' + sigpart)
25
26 def get_functionNameFromLine(str):
27 for regex in (regex_func, regex_sub):
28 match=regex.search(str)
29 if match:
30 return match.group(1)
31
32 def get_allFunctionNames():
33 names=[]
34 lines=string.split(content, "\n")
35 count=0
36 for line in lines:
37 funcname=get_functionNameFromLine(line)
38 if funcname:
39 names.append((funcname, count))
40 count=count+1
41 return names
42
43 names=get_allFunctionNames()
44
45 # ---------------------------------------------------------
46
47
48 # dump names
49 print names
50
51 # iterate through names
52 for name in names:
53 print name
54

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed