1 #exe = 1
2 #norun = 1
3 #gefile = 0
4 #libdir = %EXEPATH%\lib
5 #libdir1 = %EXEPATH%\..\lib\vis
6 #include = %EXEPATH%\lib\stdlib.ge
7 //#wait = 1
8 /******************************************************************************
9 *
10 * Copyright (C) 2009, The Gentee Group. All rights reserved.
11 * This file is part of the Gentee open source project - http://www.gentee.com.
12 *
13 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
14 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
15 * ACCEPTANCE OF THE AGREEMENT.
16 *
17 * Author: Alexander Antypenko ( santy )
18 *
19 ******************************************************************************/
20 include
21 {
22 $"Pcre.g"
23 }
24
25
26 func pcre_demo <main>
27 {
28 str version,sPattern //,sText
29 str data,sDataConv
30 int inData
31 arrstr allData
32 pcre reData
33
34 data = reData.re_version()
35
36 //print("data "+data+" \n")
37
38 version = "Version " + data
39 print("Using pcre.dll "+version +" \n")
40 print("----------------------------------------------\n \n")
41
42 ///////////////// MATCHGETALL
43
44 reData.srcText ="www.google.com www.yahoo.com 192.8.23.226 YES UP NO"
45 sPattern = "(\\w+\\.\\w+\\.\\w+)\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s+(\\w+).+\\s+(\\w+).*$"
46
47 print("Subject is ... "+ reData.srcText + " \n")
48 print("Pattern is ... "+ sPattern + "\n")
49
50 inData = reData.matchGetAll (sPattern, $PCRE_NOTEMPTY,allData)
51
52 if (inData == $NULL) : print("No match! \n")
53 elif (inData>0)
54 {
55 uint j;
56 fornum j=0,*allData
57 {
58 sDataConv.clear();
59 sDataConv.out4("%d",j);
60 print("Capured substring # "+sDataConv+" "+allData[j]+"\n")
61 }
62 }
63 print("----------------------------------------------\n \n")
64 getch()
65 // Get file name from full path
66 allData.clear();
67 reData.srcText = "C:\\Program Files\\Gentee\\bin\\gentee.exe"
68 sPattern = "([^/:\\\\]+)$"
69
70 print("Subject is ... "+ reData.srcText + " ")
71 print("Pattern is ... "+ sPattern + "\n")
72
73 inData = reData.matchGetAll (sPattern, $PCRE_NOTEMPTY,allData)
74 if (inData == $NULL) : print("No match!\n")
75 elif (inData>0)
76 {
77 uint j;
78 fornum j=0,*allData
79 {
80 sDataConv.clear();
81 sDataConv.out4("%d",j);
82 print("Capured substring #"+sDataConv+" "+allData[j]+"\n")
83 }
84 }
85 print("----------------------------------------------\n \n")
86 getch()
87
88 // Get drive letter from full path
89 allData.clear();
90 reData.srcText = "C:\\Program Files\\gentee\\bin\\gentee.exe"
91 sPattern = "^\\s*([^:])"
92 print("Subject is ... "+ reData.srcText + " ")
93 print("Pattern is ... "+ sPattern + "\n")
94
95 inData = reData.matchGetAll (sPattern, $PCRE_NOTEMPTY,allData)
96 if (inData == $NULL) : print("No match! \n")
97 elif (inData>0)
98 {
99 uint j;
100 fornum j=0,*allData
101 {
102 sDataConv.clear();
103 sDataConv.out4("%d",j);
104 print("Capured substring #"+sDataConv+" "+allData[j]+"\n")
105 }
106 }
107 print("----------------------------------------------\n \n")
108 getch()
109 /// wrong
110 reData.srcText = "foooooo fo foa boo boa"
111 sPattern = "((foo)" // example of a wrong pattern
112 allData.clear();
113 print("Subject is ... "+ reData.srcText + " ")
114 print("Pattern is ... "+ sPattern + "\n")
115
116 inData = reData.matchGetAll (sPattern, $PCRE_NOTEMPTY,allData)
117 if (inData == $NULL) : str_print("No match!\n")
118 elif (inData>0)
119 {
120 uint j;
121 fornum j=0,*allData
122 {
123 sDataConv.clear();
124 sDataConv.out4("%d",j);
125 print("Capured substring #"+sDataConv+" "+allData[j]+"\n")
126 }
127 }
128 print("----------------------------------------------\n \n")
129 getch()
130 ///////////////// MATCH
131
132 // This is a match because we don't check for word boudaries
133 reData.srcText = "foooooo fo foa boo boa"
134 sPattern = "foo"
135
136 print("Subject is ... "+ reData.srcText + " ")
137 print("Pattern is ... "+ sPattern + "\n")
138
139 inData = reData.match(sPattern, $PCRE_NOTEMPTY)
140
141 sDataConv.clear();
142 sDataConv.out4("%d",inData);
143 print("Result "+sDataConv+" match found \n")
144
145 print("----------------------------------------------\n \n")
146 getch()
147 // This is a no match because there is no single word "foo"
148
149 reData.srcText = "foooooo fo foa boo boa"
150 sPattern = "\\bfoo\\b"
151
152 print("Subject is ... "+ reData.srcText + " ")
153 print("Pattern is ... "+ sPattern + "\n")
154
155 //print("MATCH 0\n")
156 inData = reData.match(sPattern, $PCRE_NOTEMPTY)
157 //print("MATCH 1\n")
158 sDataConv.clear();
159 sDataConv.out4("%d",inData);
160 print("Result "+sDataConv+" match found \n")
161
162 print("----------------------------------------------\n \n")
163 getch()
164 }
165