equivalencia Wild2RegEx

equivalencia Wild2RegEx

Postby horacio » Mon Sep 11, 2017 1:05 pm

Colegas estoy portando una aplicación hecha con xharbour a harbour y Wild2RegEx no existe esta función, hay alguna equivalente ? Muchas Gracias.

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: equivalencia Wild2RegEx

Postby karinha » Mon Sep 11, 2017 2:42 pm

Horácio, para que sirve Wild2RegEx de xHarbour? Gracias, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: equivalencia Wild2RegEx

Postby horacio » Mon Sep 11, 2017 3:05 pm

Hola Joao. Convierte una cadena de caracteres incluyendo caracteres comodín a una expresión regular

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: equivalencia Wild2RegEx

Postby karinha » Mon Sep 11, 2017 3:14 pm

Code: Select all  Expand view

c:\hbb\source\rtl\regex.c
HB_FUNC( HB_ATX )
HB_FUNC( WILD2REGEX )
HB_FUNC( HB_REGEX )
HB_FUNC( HB_REGEXATX )
HB_FUNC( HB_REGEXALL )
HB_FUNC( HB_REGEXMATCH )
HB_FUNC( HB_REGEXSPLIT )
HB_FUNC( HB_REGEXCOMP )
HB_FUNC( HB_ISREGEXSTRING )
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: equivalencia Wild2RegEx

Postby karinha » Mon Sep 11, 2017 3:16 pm

Ejemplo en harbour. Mira se es esto:

Code: Select all  Expand view

// 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 succeeds", ;
      "Could be 1999/534/12, but this will fail" }

   CLS

   @ 0, 15 SAY "Regular expression scan tests"
   /*
   * Standard regex to get the ISO date format:
   * ([0-9]{4}): exactly four 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 ! 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: " + hb_ntos( cStr[ 2 ] ) + ;
            " End: " + hb_ntos( cStr[ 3 ] )
         nRow++
      NEXT
      nRow++
   ENDIF

   @ nRow, 1
   @ MaxRow(), 25 SAY "Press a key to continue"
   Inkey( 0 )

   RETURN
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: equivalencia Wild2RegEx

Postby karinha » Mon Sep 11, 2017 3:21 pm

Code: Select all  Expand view

// 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
 


Saludos
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: equivalencia Wild2RegEx

Postby karinha » Mon Sep 11, 2017 3:22 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: equivalencia Wild2RegEx

Postby horacio » Mon Sep 11, 2017 7:43 pm

Gracias Joao por tus respuestas. Mañana cuando llegue a la empresa pruebo y comento

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 40 guests