[Gambas-user] I don't think regexp is working correctly, wrong number of fields are returned

Brian G brian at westwoodsvcs.com
Mon Oct 9 01:56:08 CEST 2023


When Using regexp, the last field is never captured, unless I am just doing something wrong? 
Has anyone else experienced this behavior? 

Using; 

Dim MyReg As New Regexp 
Dim searchstr As String = "(^.*)" & "@mock" & "[(](.*)[)](.*)" 
MyReg.Compile(searchstr, (RegExp.MultiLine Or RegExp.Caseless)) 
Dim data = "@mock(\"apple\",\"pear\",2 ,3 ,4 ) 'this is a comment" 
MyReg.Exec(data) 

outputs: 
Count = 3 
Field 0 = "@mock(\"apple\",\"pear\",2 ,3 ,4 ) 'this is a comment" 
Field 1 = "" 
Field 2 = "\"apple\",\"pear\",2 ,3 ,4 " 

Dim MyReg As New Regexp 
Dim searchstr As String = "(^.*)" & "@mock" & "[(](.*)[)](.*)()" ' add an extra dummy field 
MyReg.Compile(searchstr, (RegExp.MultiLine Or RegExp.Caseless)) 
Dim data = "@mock(\"apple\",\"pear\",2 ,3 ,4 ) 'this is a comment" 
MyReg.Exec(data) 

Outputs: 
Count = 3 
Field 0 = "@mock(\"apple\",\"pear\",2 ,3 ,4 ) 'this is a comment" 
Field 1 = "" 
Field 2 = "\"apple\",\"pear\",2 ,3 ,4 " 
Field 3 = " 'this is a comment" 


"Failure is the key to success; 
each mistake teaches us something" .. Morihei Ueshiba 
Brian G 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231008/a7447351/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestRegExpFields-0.0.1.tar.gz
Type: application/x-gzip
Size: 4112 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231008/a7447351/attachment-0001.bin>


More information about the User mailing list