Desde el arc贸n de los recuerdos te posteo el c贸digo de regex.prg que pertenece a xHarbour ( no s茅 cual versi贸n )
* regex.prg
* $Id: regex.prg,v 1.4 2003/05/27 20:05:54 jonnymind Exp $
* Test for regular expression functions
*
* Giancarlo Niccolai
*
PROCEDURE Main()
聽 聽LOCAL regex
聽 聽LOCAL aMatch
聽 聽LOCAL cStr, nRow := 2, nCol
聽 聽LOCAL aSource := { ;
聽 聽 聽 "First date to match: 2001-3-21", ;
聽 聽 聽 "2002-12/2", ;
聽 聽 聽 "Another can be 1999/5/12, and suceeds", ;
聽 聽 聽 "Could be 1999/534/12, but this will fail" ;
聽 聽}
聽 聽CLEAR SCREEN
聽 聽@0,15 SAY "X H A R B O U R - Regular expression scan tests"
聽 聽/*
聽 聽* Standard regex to get the ISO date format:
聽 聽* ([0-9]{4}): exactly fuor digits (year); it is in brackets,
聽 聽* 聽 聽this means that we want it back as a group
聽 聽* [-/]: one bar or a minus
聽 聽* ([0-9]{1,2}): one or two digits
聽 聽*/
聽 聽regex := HB_RegexComp( "([0-9]{4})[-/]([0-9]{1,2})[-/]([0-9]{1,2})" )
聽 聽FOR EACH cStr IN aSource
聽 聽 聽 @nRow, 5 SAY "String is '" + cStr + "'"
聽 聽 聽 nRow ++
聽 聽 聽 aMatch := HB_Regex( regex, cStr )
聽 聽 聽 IF .not. Empty( aMatch )
聽 聽 聽 聽 聽@nRow, 10 SAY "Matched: " + aMatch[1] + " ( Year: " + aMatch[2] + ", Month: " +;
聽 聽 聽 聽 聽 聽 aMatch[3] + ", Day: " + aMatch[4] + ")"
聽 聽 聽 ELSE
聽 聽 聽 聽 聽@nRow, 10 SAY "Match FAILED!"
聽 聽 聽 ENDIF
聽 聽 聽 nRow += 2
聽 聽NEXT
聽 聽cStr := "searching 'regex' here:"
聽 聽@nRow, 5 SAY "A test of a regex compiled on the fly; " + cStr
聽 聽aMatch := HB_Regex( "(.*)regex(.*)", cStr )
聽 聽nRow++
聽 聽IF Empty( aMatch )
聽 聽 聽 @ nRow, 10 SAY "NOT FOUND!"
聽 聽ELSE
聽 聽 聽 @ nRow, 10 SAY "Found (Before: <<" + aMatch[2] + ">>, After: <<" + aMatch[3] + ">>)"
聽 聽ENDIF
聽 聽nRow+=2
聽 聽cStr := "A str; with: separators :; here "
聽 聽@nRow, 5 SAY "Split test; splitting '" + cStr + "' by ':|;'"
聽 聽nRow++
聽 聽aMatch := HB_RegexSplit( ":|;", cStr )
聽 聽IF Empty( aMatch )
聽 聽 聽 @nRow++, 10 SAY "Test failed"
聽 聽ELSE
聽 聽 聽 nCol := 10
聽 聽 聽 FOR EACH cStr in aMatch
聽 聽 聽 聽 聽@nRow, nCol SAY cStr + "/"
聽 聽 聽 聽 聽nCol += Len( cStr ) +1
聽 聽 聽 NEXT
聽 聽 聽 nRow++
聽 聽ENDIF
聽 聽cStr := "A string without separators"
聽 聽@nRow, 5 SAY "Split test; splitting '" + cStr + "' by ':|;'"
聽 聽nRow++
聽 聽aMatch := HB_RegexSplit( ":|;", cStr )
聽 聽IF Empty( aMatch )
聽 聽 聽 @nRow++, 10 SAY "Test failed"
聽 聽ELSE
聽 聽 聽 nCol := 10
聽 聽 聽 FOR EACH cStr in aMatch
聽 聽 聽 聽 聽@nRow, nCol SAY cStr + "/"
聽 聽 聽 聽 聽nCol += Len( cStr ) +1
聽 聽 聽 NEXT
聽 聽 聽 nRow++
聽 聽ENDIF
聽 聽cStr := "Test for RegexAtx"
聽 聽@nRow, 5 SAY "RegexAtx test; scanning '" + cStr + "' by 'Reg(.x)'"
聽 聽nRow++
聽 聽aMatch := HB_RegexAtx( "Reg(.x)", cStr )
聽 聽IF Empty( aMatch )
聽 聽 聽 @nRow++, 10 SAY "Test failed"
聽 聽ELSE
聽 聽 聽 nCol := 15
聽 聽 聽 FOR EACH cStr in aMatch
聽 聽 聽 聽 聽@nRow, nCol SAY "FOUND: '"+cStr[1] + "' Start: " + AllTrim( Str(cStr[2]) )+;
聽 聽 聽 聽 聽 聽 " End: " + Alltrim( Str( cStr[3] ) )
聽 聽 聽 聽 聽nRow++
聽 聽 聽 NEXT
聽 聽 聽 nRow++
聽 聽ENDIF
聽 聽@nRow, 1
聽 聽@24, 25 SAY "Press a key to continue"
聽 聽Inkey( 0 )
RETURN
Espero te sirva. Saludos