I've been having an issue getting the results I want from the REGEXPR function so
I wrote a barebones regular expression tester.
It allows you to put in the text you want to process, add your regular expression
string and see the results right away. This allows you to fine tune your expression
so that you get the results you want.
-Kevin
------------------
Zimbi Inc.
I wrote a barebones regular expression tester.
It allows you to put in the text you want to process, add your regular expression
string and see the results right away. This allows you to fine tune your expression
so that you get the results you want.
-Kevin
Code:
'****************************************************** ' Regular Expression Tester ' ' Allows you to test regular expressions for proper ' results ' ' @Author: Kevin Voell ' @Date: 6-11-2006 ' '****************************************************** #COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" %IDC_BUTTON_SEARCH = 108 %IDC_EXPRESSION_LABEL = 107 %IDC_LABEL_RESULTS = 106 %IDC_LABEL_SEARCH_TEXT = 105 %IDC_LISTBOX_RESULTS = 104 %IDC_SEARCH_TEXT = 103 %IDC_TEXTBOX_SEARCH_TEXT = 102 %IDD_REGULAR_EXPRESSION = 101 $Default_Regular_Expression = "Disallow[a-zA-Z0-9 -_=]+" DECLARE CALLBACK FUNCTION REGULAR_EXPRESSION_PROC() DECLARE FUNCTION SHOW_MAIN_DIALOG(BYVAL hParent AS DWORD) AS LONG DECLARE FUNCTION Preform_Regular_Expression(BYVAL hDlg AS LONG) AS LONG '***************************************************** 'Main entry point FUNCTION PBMAIN() SHOW_MAIN_DIALOG(%HWND_DESKTOP) END FUNCTION '****************************************************** ' Our main callback CALLBACK FUNCTION REGULAR_EXPRESSION_PROC() SELECT CASE AS LONG CBMSG CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND SELECT CASE AS LONG CBCTL CASE %IDC_BUTTON_SEARCH IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN Preform_Regular_Expression(CBHNDL) END IF END SELECT END SELECT END FUNCTION '**************************************************************** ' This function will get the regular expression text that was ' entered into the text box and preform a REGEXPR using it. FUNCTION Preform_Regular_Expression(BYVAL hDlg AS LONG) AS LONG LOCAL lPosition AS LONG LOCAL lLength AS LONG LOCAL sText_Result AS STRING LOCAL sRegular_Expression AS STRING LOCAL sSearch_Text AS STRING LOCAL iFound_Flag AS INTEGER 'Get the regular expression text CONTROL GET TEXT hDlg, %IDC_SEARCH_TEXT TO sRegular_Expression 'Get the text to search CONTROL GET TEXT hDlg, %IDC_TEXTBOX_SEARCH_TEXT TO sSearch_Text 'Clear out any previous results CONTROL SEND hDlg, %IDC_LISTBOX_RESULTS, %LB_RESETCONTENT, 0, 0 DO 'Preform the regular Expression REGEXPR sRegular_Expression IN sSearch_Text AT lPosition + lLength TO lPosition, lLength IF lPosition <> 0 THEN 'display the string that was found in our listbox LISTBOX ADD hDlg, %IDC_LISTBOX_RESULTS, MID$(sSearch_Text, lPosition, lLength) iFound_Flag = 1 END IF LOOP WHILE lPosition IF iFound_Flag = 0 THEN LISTBOX ADD hDlg, %IDC_LISTBOX_RESULTS, "No matches found" END IF END FUNCTION '************************************************************** ' Display our main dialog FUNCTION SHOW_MAIN_DIALOG(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD LOCAL sRegular_Expression_Test AS STRING sRegular_Expression_Test = "# Zimbi Generated Robots.txt" & $CRLF _ & "# Robot Exclusion File -- robots.txt" & $CRLF _ & "# Author: Kevin Voell" & $CRLF _ & "# Last Updated : December 31, 2005" & $CRLF _ & "User-Agent: *" & $CRLF _ & "Disallow: /" & $CRLF _ & "Disallow: /img/" & $CRLF _ & "Disallow: /images/" & $CRLF _ & "Disallow: /includes/" 'Create our main dialog DIALOG NEW hParent, "Regular Expression Tester", 70, 70, 587, 272, _ %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _ %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg 'create the control that holds the text we want to search CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX_SEARCH_TEXT, _ sRegular_Expression_Test, 5, 50, 280, 219, %WS_CHILD OR _ %WS_VISIBLE OR %WS_TABSTOP OR %ES_LEFT OR %ES_MULTILINE OR _ %ES_AUTOHSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR 'create the control that holds our regular expression CONTROL ADD TEXTBOX, hDlg, %IDC_SEARCH_TEXT, _ $Default_Regular_Expression, 80, 10, 270, 15 'create our search button CONTROL ADD BUTTON, hDlg, %IDC_BUTTON_SEARCH, "Search", 365, 10, 70, 15 'create the control that holds our output CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX_RESULTS, , 295, 50, 285, 219 'lables CONTROL ADD LABEL, hDlg, %IDC_EXPRESSION_LABEL, "Regular Expression", _ 5, 10, 70, 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR _ %SS_CENTERIMAGE, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD LABEL, hDlg, %IDC_LABEL_SEARCH_TEXT, "Search Text:", 5, 35, _ 110, 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD LABEL, hDlg, %IDC_LABEL_RESULTS, "Results:", 295, 35, 115, _ 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING 'Show our dialog DIALOG SHOW MODAL hDlg, CALL REGULAR_EXPRESSION_PROC TO lRslt FUNCTION = lRslt END FUNCTION'****************************************************** ' Regular Expression Tester ' ' Allows you to test regular expressions for proper ' results ' ' @Author: Kevin Voell ' @Date: 6-11-2006 ' '****************************************************** #COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" %IDC_BUTTON_SEARCH = 108 %IDC_EXPRESSION_LABEL = 107 %IDC_LABEL_RESULTS = 106 %IDC_LABEL_SEARCH_TEXT = 105 %IDC_LISTBOX_RESULTS = 104 %IDC_SEARCH_TEXT = 103 %IDC_TEXTBOX_SEARCH_TEXT = 102 %IDD_REGULAR_EXPRESSION = 101 $Default_Regular_Expression = "Disallow[a-zA-Z0-9 -_=]+" DECLARE CALLBACK FUNCTION REGULAR_EXPRESSION_PROC() DECLARE FUNCTION SHOW_MAIN_DIALOG(BYVAL hParent AS DWORD) AS LONG DECLARE FUNCTION Preform_Regular_Expression(BYVAL hDlg AS LONG) AS LONG '***************************************************** 'Main entry point FUNCTION PBMAIN() SHOW_MAIN_DIALOG(%HWND_DESKTOP) END FUNCTION '****************************************************** ' Our main callback CALLBACK FUNCTION REGULAR_EXPRESSION_PROC() SELECT CASE AS LONG CBMSG CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND SELECT CASE AS LONG CBCTL CASE %IDC_BUTTON_SEARCH IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN Preform_Regular_Expression(CBHNDL) END IF END SELECT END SELECT END FUNCTION '**************************************************************** ' This function will get the regular expression text that was ' entered into the text box and preform a REGEXPR using it. FUNCTION Preform_Regular_Expression(BYVAL hDlg AS LONG) AS LONG LOCAL lPosition AS LONG LOCAL lLength AS LONG LOCAL sText_Result AS STRING LOCAL sRegular_Expression AS STRING LOCAL sSearch_Text AS STRING LOCAL iFound_Flag AS INTEGER 'Get the regular expression text CONTROL GET TEXT hDlg, %IDC_SEARCH_TEXT TO sRegular_Expression 'Get the text to search CONTROL GET TEXT hDlg, %IDC_TEXTBOX_SEARCH_TEXT TO sSearch_Text 'Clear out any previous results CONTROL SEND hDlg, %IDC_LISTBOX_RESULTS, %LB_RESETCONTENT, 0, 0 DO 'Preform the regular Expression REGEXPR sRegular_Expression IN sSearch_Text AT lPosition + lLength TO lPosition, lLength IF lPosition <> 0 THEN 'display the string that was found in our listbox LISTBOX ADD hDlg, %IDC_LISTBOX_RESULTS, MID$(sSearch_Text, lPosition, lLength) iFound_Flag = 1 END IF LOOP WHILE lPosition IF iFound_Flag = 0 THEN LISTBOX ADD hDlg, %IDC_LISTBOX_RESULTS, "No matches found" END IF END FUNCTION '************************************************************** ' Display our main dialog FUNCTION SHOW_MAIN_DIALOG(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD LOCAL sRegular_Expression_Test AS STRING sRegular_Expression_Test = "# Zimbi Generated Robots.txt" & $CRLF _ & "# Robot Exclusion File -- robots.txt" & $CRLF _ & "# Author: Kevin Voell" & $CRLF _ & "# Last Updated : December 31, 2005" & $CRLF _ & "User-Agent: *" & $CRLF _ & "Disallow: /" & $CRLF _ & "Disallow: /img/" & $CRLF _ & "Disallow: /images/" & $CRLF _ & "Disallow: /includes/" 'Create our main dialog DIALOG NEW hParent, "Regular Expression Tester", 70, 70, 587, 272, _ %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _ %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg 'create the control that holds the text we want to search CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX_SEARCH_TEXT, _ sRegular_Expression_Test, 5, 50, 280, 219, %WS_CHILD OR _ %WS_VISIBLE OR %WS_TABSTOP OR %ES_LEFT OR %ES_MULTILINE OR _ %ES_AUTOHSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR 'create the control that holds our regular expression CONTROL ADD TEXTBOX, hDlg, %IDC_SEARCH_TEXT, _ $Default_Regular_Expression, 80, 10, 270, 15 'create our search button CONTROL ADD BUTTON, hDlg, %IDC_BUTTON_SEARCH, "Search", 365, 10, 70, 15 'create the control that holds our output CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX_RESULTS, , 295, 50, 285, 219 'lables CONTROL ADD LABEL, hDlg, %IDC_EXPRESSION_LABEL, "Regular Expression", _ 5, 10, 70, 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR _ %SS_CENTERIMAGE, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD LABEL, hDlg, %IDC_LABEL_SEARCH_TEXT, "Search Text:", 5, 35, _ 110, 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD LABEL, hDlg, %IDC_LABEL_RESULTS, "Results:", 295, 35, 115, _ 15, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING 'Show our dialog DIALOG SHOW MODAL hDlg, CALL REGULAR_EXPRESSION_PROC TO lRslt FUNCTION = lRslt END FUNCTION
Zimbi Inc.