//----------------------------------------------------------------------------//
// Ejemplo de uso de Expresiones Regulares
// Example of using Regular Expressions
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#include "Fivewin.ch"
//----------------------------------------------------------------------------//
Function Main()
local aSamples := { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 100, ;
101, 102, 103, 104, 105, 106, 107 }
local nOpc
local x
// One sample
nOpc := 3
RegExSample( nOpc )
// All samples
For x = 1 to Len( aSamples )
nOpc := aSamples[ x ]
RegExSample( nOpc )
Next x
Return nil
Function RegExSample( nOpc )
Local cRegEx := ""
Local aMatch
Local oItem
Local aItems := {}
Local cString := ""
Local cWords := ""
Local cWords1 := ""
Local cFile := "..\source\classes\TFivedit.prg"
DEFAULT nOpc := 0
cString := "En un lugar De la Mancha" + CRLF
cString += "de cuyo nombre no" + CRLF
cString += "quiero acordarme de" + CRLF
cString += " de eso no quiero acordarme de" + CRLF
cString += "nada de nada así que descansa mucho" + CRLF
cString += " Local oObj1 := New():MyClass( n, m )" + CRLF
cString += " Local oObj2 := New( ):MyClass( n, m )" + CRLF
cString += "cVar = (parametros)" + CRLF
cString += "cVar = ( parameters)" + CRLF
cString += "cVar = (parameters )" + CRLF
cString += "cVar = (parameters )" + CRLF
cString += "cVar = ( parameters1 )" + CRLF
cString += "cVar = 8" + CRLF
cString += "cVar := 4" + CRLF
//
cWords1 := "(activex|" + ;
"bitmap|brush|btnbmp|button|buttonbmp|buttonbar|" + ;
"checkbox|calex|clipboard|combobox|combometro|cursor|" + ;
"dbcombo|dialog|dtpicker|" + ;
"edit|explorerbar|" + ;
"flatbtn|folder|folderex|font|" + ;
"get|graph|group|" + ;
"icon|image|imagelist|imgbitmap|" + ;
"layout|listbox|listview|" + ;
"mail|metafile|meter|meterex|msgbar|msgitem|" + ;
"outlook|" + ;
"panel|pen|progress|" + ;
"radio|radioitem|rebar|ribbonbar|richedit|richedit5|" + ;
"say|saybarcode|scrollbar|scrollmsg|scrollmetro|selector|slider|" + ;
"splitter|statusbar|switch|" + ;
"tabcontrol|tbbutton|tbmenu|tbseparator|timer|" + ;
"tmpicker|toolbar|trackbar|treeview|" + ;
"windows|" + ;
"ximage|xbrowse)"
Do Case
Case nOpc = 1
// Buscar una linea que empiece por...
cWords := "de"
cRegEx := '^' + cWords
Case nOpc = 2
// Buscar una linea que empiece por... ( con espacios o no delante )
cWords := "de"
cRegEx := '^\s*' + cWords
Case nOpc = 3
// Buscar una Palabra que empiece por...
cString := MemoRead( cFile )
cWords := "new"
cRegEx := '\b' + cWords
Case nOpc = 4
// Buscar una Palabra completa
cWords := "de"
cRegEx := '\b' + cWords + '\b'
Case nOpc = 5
// Buscar todas las palabras
cWords := ""
cRegEx := '\w+' // es lo mismo que: '[a-z0-9_]+'
Case nOpc = 6
// Buscar si exite := ó =
cWords := "cvar"
cRegEx := '\b' + cWords + '\b.{0,20}:=' + "|" + '\b' + cWords + '\b.{0,20}='
Case nOpc = 7
// Buscar si exite ':=' ó '='
cWords := ".*"
cRegEx := '\b' + cWords + '\b.{0,20}:=' + "|" + '\b' + cWords + '\b.{0,20}='
Case nOpc = 8
// Buscar una(s) Palabra(s) completa(s) entre los paréntesis
cWords := ".*"
cRegEx := "\(" + cWords + "\)"
Case nOpc = 9
//
cWords := ""
cRegEx := "New\(" + cWords + "\)"
Case nOpc = 10
//
cWords := ".*"
cRegEx := "New\(" + cWords + "\)"
Case nOpc = 11
// Busca definicion de controles con @
cString := MemoRead( cFile )
cWords := "@"
cRegEx := '^\s*' + cWords + ".*" + "\b" + cWords1
Case nOpc = 12
// Busca definicion de controles con DEFINE
cString := MemoRead( cFile )
cWords := "define|redefine"
cRegEx := '^\s*' + cWords + ".*" + "\b" + cWords1
Case nOpc = 13
// Busca definicion de controles con DEFINE
cString := MemoRead( cFile )
cWords := "(database|editvars|fwconnect|ini|menu|menuitem|print|report)"
cRegEx := '^\s*' + cWords + ".*" + "\b"
Case nOpc = 14
// Busca definicion de controles con DEFINE
cString := MemoRead( cFile )
cWords := "(include|define|xtranslate|xcommand|pragma)"
cRegEx := '^\s*#' + cWords + ".*" + "\b"
// Siguiente paso, leer lineas que contengan @ como primer caracter
// Leer lineas que tengan como primera palabra "DEFINE", ojo, que no tengan #
// Leer lineas que tengan como primera palabra "ACTIVATE" ¿?
// Todo eso para detectar qué clase estamos utilizando
Case nOpc = 100
cString := MemoRead( cFile )
cWords := "class"
cRegEx := '^\s*' + cWords + "\b" + ".*" + "\b"
Case nOpc = 101
cString := MemoRead( cFile )
cWords := "endclass"
cRegEx := '^\s*' + cWords
Case nOpc = 102
cString := MemoRead( cFile )
cWords := "classdata"
cRegEx := '^\s*' + cWords + ".*" + "\b"
Case nOpc = 103
cString := MemoRead( cFile )
cWords := "data"
cRegEx := '^\s*' + cWords + "\b" + ".*" + "\b"
Case nOpc = 104
cString := MemoRead( cFile )
cWords := ""
cRegEx := '^\s*' + "method" + ".*" + "class" + ".*"
Case nOpc = 105
cString := MemoRead( cFile )
cWords := ""
cRegEx := '^\s*' + "method" + ".*" + "inline" + ".*"
Case nOpc = 106
cString := MemoRead( cFile )
cWords := "(function|static function|func|procedure|proc|static procedure)"
cRegEx := '^\s*' + cWords + "\b" + ".*" + "\b"
Case nOpc = 107
cString := MemoRead( cFile )
cWords := "(local|private|static|public)"
cRegEx := '^\s*' + cWords + "\b" + ".*" + "\b"
EndCase
//
if !Empty( nOpc )
if !Hb_IsNil( HB_RegExComp( cRegEx, .F., ) )
//
aMatch := hb_regexAll( cRegEx, cString, .F., .T., , , .F. )
//
For Each oItem IN aMatch
//if oItem:__enumIndex == 2
// "Cadena" , "Posicion Inicial", "Posicion Final"
AAdd( aItems, { oItem[ 1, 1 ], oItem[ 1, 2 ], oItem[ 1, 3 ] } )
Next
XBrowse( aItems )
else
MsgInfo( cRegEx, "Error" )
endif
endif
//
Return nil
//----------------------------------------------------------------------------//