[Gambas-user] Help with RegExp

Benoît Minisini gambas at ...1...
Sat Sep 24 01:16:51 CEST 2011


> On Sat, 2011-09-24 at 00:14 +0200, tobias wrote:
> > hi,
> > 
> > i have a problem with regular expressions: i'm not very good in using
> > them. i want to determine the comment string in a gambas comment with
> > gb.pcre and been sitting down for 3 hours now, totally frustrated...
> > i thought, i have to search for the first ' apostrophe from the left
> > which isn't between "". i have experimented with the ugliest things but
> > nothing worked properly.
> > i used these lines to test:
> > 
> > Print "'" '"'"
> > Print "text" 'comment
> > and the line of RegExp.Compile(???) itself
> > 
> > of course, they should give
> > "'"
> > comment
> > (nothing)
> > 
> > i got a solution that matched the first two ones correctly but no chance
> > for the regexp itself in line 3 (i always got something after the
> > apostrophe in the regexp)...
> > 
> > i didn't get very far without getting wrong results, so i think there's
> > no need to post my tries
> > i would be very glad if someone more experienced could help me.
> > 
> > regards,
> > tobi
> 
> I'm not sure whether you are trying to learn regexp patterns or parse a
> gambas sourcecode line, but if the second then this is how I do it.
> 
> 
> ' Gambas module file
> 
> Public Sub Main()
> Dim sSourceCode As String     ' The original source line
> Dim sCode As String           ' The part of the source line that is code
> Dim sComment As String        ' The part of the source line that is comment
> Dim aComment As New String[]
> 
> sSourceCode = "  While surname<>\"O'Reilly\" or surname<>\"O'Malley\" Or
> surname <> \"O'Reilly-O'Malley\"          '' Loop around looking for the
> irishman called \"O'Reilly\", \"O'Malley\" or \"O'Reilly-O'Malley\""
> 
>         Print "Original==========="
>         Print sSourceCode
> 
> aComment = Split(sSourceCode, "'", "\"", False, True)
> 
>         Print "Parsed==========="
>         Print aComment.Join("\n")
> 
> sCode = Trim(aComment[0])
> aComment.Delete(0)
> sComment = Trim(aComment.Join("'"))
> 
>         Print "Code part==========="
>         Print sCode
>         Print "Comment part==========="
>         Print sComment
> 
> End
> 
> 
> regards
> Bruce
> 

Otherwise there is a Gambas syntax analyzer in the gb.eval component if you 
need...

-- 
Benoît Minisini




More information about the User mailing list