[Gambas-user] Regular expressions
Markus Schatten
markus.schatten at ...2005...
Sat Nov 1 14:01:35 CET 2008
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
More information about the User
mailing list