AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DotStar - Yet Another RegEx Tester

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Icarus



Joined: 24 Nov 2005
Posts: 441

PostPosted: Tue May 27, 2008 6:14 pm    Post subject: DotStar - Yet Another RegEx Tester Reply with quote

DotStar 0.12 - Just Another RegEx Tester (JART?)

Ok, yes, there are a thousand RegEx testers so another one could not hurt right?

Just wanted to keep it small (in code and GUI)
Leaving the Replace field empty, will do a RegExMatch (and display the captured tokens if any)
Naturally, results are updated as you type.

Code:
;-------------------------------------------------------------------------------
;  DotStar 0.12
;  Just Another RegEx Tester
;  by Danny Ben Shitrit (aka Icarus)
;-------------------------------------------------------------------------------
NameString    := "DotStar"
VersionString := "0.12"

#SingleInstance Force
#NoTrayIcon

DefaultHaystack := "The RegEx SandBox"
DefaultNeedle   := "(\w+)\s((.)(.))..(.)(..((.)(.).))(.*)"
DefaultReplace  := "$2$5 $7 $1 ${10} $8$3$4 i$9 $1$6"

Gui Margin, 4,4
Gui Color, EEEEEE, DDDDDD
Gui Font,s10
Gui Add, Text, x4 y4 w80 Section Right                     , Haystack
Gui Add, Edit, x+7 w400 r3 AltSubmit vGuiHaystack gRefresh , %DefaultHaystack%
Gui Add, Text, w80 xs y+11 Right                           , Needle
Gui Font,s14
Gui Add, Edit, x+7 yp-7 w400 AltSubmit vGuiNeedle gRefresh , % DefaultNeedle
Gui Font,s10
Gui Add, Text, w80  xs Right                               , Replace
Gui Add, Edit, x+7 w400 AltSubmit vGuiReplace gRefresh     , % DefaultReplace
Gui Add, Text, w80  xs Right                               , Result
Gui Add, Edit, x+7 w400 r8 ReadOnly  vGuiResult
Gui Add, Text, w80  xs Right                               , Errorlevel
Gui Add, Edit, x+7 w400 -wrap ReadOnly  vGuiErrorLevel
Gui Font,s8
Gui Add, Button, wp Default gGuiSubmit, Copy all to clipboard (Enter)
Gui Show,, %NameString% v%VersionString%
Gosub Refresh

Return

Refresh:
  Gui Submit, NoHide

  Loop 20
    Token%A_Index% := ""
   
  StringReplace GuiHaystack, GuiHaystack ,`n,`r`n, All
  StringReplace GuiNeedle, GuiNeedle ,``a,`a, All

  Result := GuiReplace ? RegExReplace( GuiHaystack, GuiNeedle, GuiReplace ) : RegExMatch( GuiHaystack, GuiNeedle, Token ) ? "Match`r`n" : "No Match`r`n" 
  GuiErrorLevel := Errorlevel
 
  If( RegExMatch( GuiNeedle, "\(.+\)" ) )
    Loop 20
      Result .= Token%A_Index% <> "" ? A_Index . ": " . Token%A_Index% . "`r`n" : ""

  GuiControl,,GuiResult,%Result%
  GuiControl,,GuiErrorLevel,%GuiErrorLevel%
Return

GuiEscape:
GuiClose:
  ExitApp
Return

GuiSubmit:
  Gui Submit, NoHide
  Clipboard = %GuiHaystack%`r`n%GuiNeedle%`r`n%GuiReplace%
Return



Edit: Updated version with multiline and Errorlevel display


Last edited by Icarus on Mon Jun 02, 2008 8:28 am; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
keybored



Joined: 18 Jun 2006
Posts: 90
Location: Phoenix, AZ

PostPosted: Sun Jun 01, 2008 6:51 pm    Post subject: hurray for occums razor Reply with quote

Icarus, Love the name DotStar and appreciate the simplicity.

From trying it there are only two things that might be nice. The Haystack to allow multiple lines. When copying to clipboard using `r`n may be better with some editors.

Really nice work!
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 441

PostPosted: Sun Jun 01, 2008 9:44 pm    Post subject: Reply with quote

Thanks keyboard,

Trying to make the multiline to work. I am probably missing something. It works as documented when I am using a simple "If RegExMatch" but it does not seem to work when the haystack comes from the gui.

Dont know what I am missing, too tired.
If you want, see if you can make the below work?
Code:

;-------------------------------------------------------------------------------
;  DotStar 0.11
;  Just Another RegEx Tester
;  by Danny Ben Shitrit (aka Icarus)
;-------------------------------------------------------------------------------
NameString    := "DotStar"
VersionString := "0.11"

#SingleInstance Force
#NoTrayIcon

Gui Margin, 4,4
Gui Color, EEEEEE, DDDDDD
Gui Font,s10
Gui Add, Text, x4 y4 w80 Section Right                  , Haystack
;Gui Add, Edit, x+7 w400 r3 AltSubmit vGuiHaystack gRefresh , The RegEx SandBox
Gui Add, Edit, x+7 w400 r3 AltSubmit vGuiHaystack gRefresh , xyz`r`nabc
Gui Add, Text, w80 xs y+11 Right                         , Needle
Gui Font,s14
;Gui Add, Edit, x+7 yp-7 w400 AltSubmit vGuiNeedle gRefresh, (\w+)\s((.)(.))..(.)(..((.)(.).))(.*)
Gui Add, Edit, x+7 yp-7 w400 AltSubmit vGuiNeedle gRefresh, m)^abc
Gui Font,s10
Gui Add, Text, w80  xs Right                             , Replace
;Gui Add, Edit, x+7 w400 AltSubmit vGuiReplace gRefresh   , $2$5 $7 $1 ${10} $8$3$4 i$9 $1$6
Gui Add, Edit, x+7 w400 AltSubmit vGuiReplace gRefresh   ,
Gui Add, Text, w80  xs Right                             , Result
Gui Add, Edit, x+7 w400 r8 ReadOnly  vGuiResult
Gui Font,s8
Gui Add, Button, wp Default gGuiSubmit, Copy all to clipboard (Enter)
Gui Show,, %NameString% v%VersionString%
Gosub Refresh

Return

Refresh:
  Gui Submit, NoHide
  Loop 20
    Token%A_Index% := ""

  Result := ( GuiReplace <> "" ) ? RegExReplace( GuiHaystack, GuiNeedle, GuiReplace ) : ( RegExMatch( GuiHaystack, GuiNeedle, Token ) ) ? "Match`n" : "No Match`n" 
 
  If( RegExMatch( GuiNeedle, "\(.+\)" ) )
    Loop 20
      Result .= Token%A_Index% <> "" ? A_Index . ": " . Token%A_Index% . "`r`n" : ""

  GuiControl,,GuiResult,%Result%
Return

GuiEscape:
GuiClose:
  ExitApp
Return

GuiSubmit:
  Gui Submit, NoHide
  Clipboard = %GuiHaystack%`r`n%GuiNeedle%`r`n%GuiReplace%
Return


EDIT: Posted a newer version on the first post, which seems to work.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group