Files
harbour-core/tests/regex2.prg
vszakats 9687850865 2013-03-16 02:10 UTC+0100 Viktor Szakats (harbour syenar.net)
* (all files)
    * stripped svn header
    * minor cleanups
    ; use following command to find out the history of files:
       git log
       git log --follow
       git blame
       git annotate
2013-03-16 02:11:42 +01:00

59 lines
1.2 KiB
Plaintext

// Test for regular expression functions
// This allows to use a fine tune regex to use them in programs
// Giancarlo Niccolai
#include "inkey.ch"
PROCEDURE Main()
LOCAL pCompiled
LOCAL cRegex
LOCAL cSentence
LOCAL nRow
LOCAL aMatch, cMatch
LOCAL GetList := {}
SET CONFIRM ON
CLS
@ 2, 15 SAY "Regular expression test"
@ 4, 5 SAY "Insert regular expression(s) and strings to test for."
@ 5, 5 SAY "Press <Esc> to exit"
cRegex := Space( 60 )
cSentence := Space( 120 )
DO WHILE LastKey() != K_ESC
@ 8, 5 SAY "REGEX : " GET cRegex PICTURE "@S30"
@ 9, 5 SAY "PHRASE: " GET cSentence PICTURE "@S60"
READ
IF LastKey() != K_ESC
@ 12, 5 CLEAR TO MaxRow(), MaxCol()
pCompiled := hb_regexComp( RTrim( cRegex ) )
IF Empty( pCompiled )
@ 12, 5 SAY "Invalid REGEX expression"
LOOP
ENDIF
aMatch := hb_regex( pCompiled, RTrim( cSentence ) )
IF aMatch != NIL
@ 12, 5 SAY "MATCHES:"
nRow := 13
FOR EACH cMatch IN aMatch
@ nRow++, 5 SAY ">" + cMatch
NEXT
ELSE
@ 12, 5 SAY "No matches"
ENDIF
ENDIF
ENDDO
CLS
RETURN