Re: [Gambas-user] Regular Expressions :: Error with gb.pcre component
Le 25/04/2012 18:58, Daniel Quintero a écrit : Hello, I have an error in this line of code when I use the \s constant in the pattern: re = New Regexp(sText, span\s([^]*)) If I use span([^]*) (Without the \s) I have no error. The error occurs when I press the F5 function key to execute the program. This is the error text: This application has raised an unexpected error and must abort. [11] Unknown symbol 'Editor' in class 'FForm'. Project.CompileError.2072 And this is the complete code: Public Sub Button1_Click() Dim re As Regexp Dim sText As String = TextArea1.Text Dim matches As New String[] Dim i As Integer ' Error with de \s constant in the pattern re = New Regexp(sText, span\s([^]*)) Do While re.offset= 0 And sText matches.push(re.text) If Len(sText) Len(re.text) Then sText = Mid(sText, re.offset + Len(re.text) + 1) Else sText = End If If sText Then re.exec(sText) Loop For i = 0 To matches.Max Print matches[i] Next End I have attached the project to more clarity. Thanks. *_* *Lic. Daniel Quintero Rojas* http://www.dquinter.com.mx http://futbol.dquinter.com.mx http://twitter.com/#!/dquinteror *¡Saludos desde México!** * This is a bug in the compiler and in your code. Do you use the last revision? If not, just fix your regular expression by quoting the '\' with another '\' (because '\' is both the quoting character in Gambas string and in regular expressions!) Regards, -- Benoît Minisini -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Regular Expressions :: Error with gb.pcre component
Mmm, I updated my Gambas 3.1 last week, I don't know exactly what revision is, but is recent. Ok, I will fix my code. Thanks. *_* *Lic. Daniel Quintero Rojas* http://www.dquinter.com.mx http://futbol.dquinter.com.mx http://twitter.com/#!/dquinteror *¡Saludos desde México!** * 2012/4/25 Benoît Minisini gam...@users.sourceforge.net Le 25/04/2012 18:58, Daniel Quintero a écrit : Hello, I have an error in this line of code when I use the \s constant in the pattern: re = New Regexp(sText, span\s([^]*)) If I use span([^]*) (Without the \s) I have no error. The error occurs when I press the F5 function key to execute the program. This is the error text: This application has raised an unexpected error and must abort. [11] Unknown symbol 'Editor' in class 'FForm'. Project.CompileError.2072 And this is the complete code: Public Sub Button1_Click() Dim re As Regexp Dim sText As String = TextArea1.Text Dim matches As New String[] Dim i As Integer ' Error with de \s constant in the pattern re = New Regexp(sText, span\s([^]*)) Do While re.offset= 0 And sText matches.push(re.text) If Len(sText) Len(re.text) Then sText = Mid(sText, re.offset + Len(re.text) + 1) Else sText = End If If sText Then re.exec(sText) Loop For i = 0 To matches.Max Print matches[i] Next End I have attached the project to more clarity. Thanks. *_* *Lic. Daniel Quintero Rojas* http://www.dquinter.com.mx http://futbol.dquinter.com.mx http://twitter.com/#!/dquinteror *¡Saludos desde México!** * This is a bug in the compiler and in your code. Do you use the last revision? If not, just fix your regular expression by quoting the '\' with another '\' (because '\' is both the quoting character in Gambas string and in regular expressions!) Regards, -- Benoît Minisini -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Regular expressions
Just if someone needs it, I've added an optional argument submatchindex that will return the matches of a given submatch. PRIVATE FUNCTION FindAll(subj AS String, pattern AS String, OPTIONAL submatchindex AS Integer = 0) AS String[] DIM re AS Regexp DIM matches AS NEW String[] re = NEW Regexp(subj, pattern) DO WHILE re.offset = 0 AND subj IF submatchindex = 0 THEN matches.push(re.Text) ELSE matches.push(re.SubMatches[submatchindex].Text) END IF IF Len(subj) Len(re.text) THEN subj = Mid(subj, re.offset + Len(re.text) + 1) ELSE subj = END IF IF subj THEN re.exec(subj) LOOP RETURN matches END Best regards, -- Markus Schatten, MSc Faculty of Organization and Informatics Varaždin, Croatia http://www.foi.hr - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Regular expressions
On Thursday 30 October 2008 23:32:09 Rob wrote: On Thursday 30 October 2008 17:59, Markus Schatten wrote: I'm a newbee to Gambas and I have a little problem. I would like to use the pcre Regexp class, but I seem not to be able to find any examples of how to instantiate a new object nor how to use such objects. Is there any documentation/tutorial/example? If not could please someone post a short example on how to use it? Yeah, I updated the wiki a few weeks ago with some documentation. See if it's what you need and tell me if it isn't. http://gambasdoc.org/help/comp/gb.pcre Here is the page about instantiation, to which I just added a brief example: http://gambasdoc.org/help/comp/gb.pcre/regexp/_new Thanks a lot for the links, they were very helpfull. Is there a way to use a regex for looping through all matches? Something like scan() in a for each loop or findall in python-re? I was able to figure out that the Text property holds the first match, Submatches is an array of given submatches (in parenthesis) and Offset holds the index if the first match. There seem to be no other properties defined... Best regards, -- Markus Schatten, MSc Faculty of Organization and Informatics Varaždin, Croatia http://www.foi.hr - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
[Gambas-user] Regular expressions
Hello group members, I'm a newbee to Gambas and I have a little problem. I would like to use the pcre Regexp class, but I seem not to be able to find any examples of how to instantiate a new object nor how to use such objects. Is there any documentation/tutorial/example? If not could please someone post a short example on how to use it? Best regards, -- Markus Schatten, MSc Faculty of Organization and Informatics Varaždin, Croatia http://www.foi.hr - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user