Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

dR's Simple RegExTester v0.2.1 - AHK Basic/AHK_L 32bit (A/U)


  • Please log in to reply
27 replies to this topic
derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

Hi all,

i think a pic tells more than thousands of words... ( funny enough this was also the opening for some other regex tool by pokercurious)

Simple RegExTester v 0.2.1



Fixes in 0.2.1!

  • Added Instant chk feature see live updates of haystack while designing the regex thx, IsNull use this feature wisely. having named subpatterns may freeze the script while typing or result in other unwanted behaviour
  • Fixed source update, so it doesn't reset to the default text, thx tidbit Most important new features from 0.2.0!
  • Subpattern highlighting - up to 10 subpatterns may be colored
  • Replacement Mode, supports showing the replaced Text
  • Startposition and Replace count
  • Custom color sets (save yours and load others)
  • Replacemode may modify Haystack
  • Custom PCRE Options
  • UI Redesign



The autoupdate feature is back. however it is not on by default - it works in most cases, but in rare scenarios, e.g. when having (?<>) as a regex and defining the name of the subpattern to be, it might lock up the script or lag it otherwise.
Currently named subpatterns are not supported to be color customized. also a safe escaping function is missing for the display of the haystack, that is when your text contains backslashes they might screw the script. the P-RegEx Option is not supported, it will get stripped out from the options if you enter it by hand.
Allthough one might think, when running in AHK_L this tool automagically supports unicode that is not true. the richedit control is set to ansi mode as a real good alternative for handling unicode issues is not available yet. see the source's documentation why.



To change a color of a subpattern, click at the color tab, highlight your desired pattern, and click that big fat change button. when you've selected a new color from the upcoming dialogue, its set. you may either save it or reset it to the standard. Here's a lil preset of how a custom color set may look like:

cf1 := "\red255\green255\blue164;" ; cf1 hilight matchall
cf3 := "\red128\green0\blue128;" ; cf3 replacement
cf4 := "\red128\green255\blue0;" ; cf4 pattern1
cf5 := "\red0\green128\blue128;" ; cf5 pattern2
cf6 := "\red0\green64\blue0;" ; cf6 pattern3
cf7 := "\red64\green128\blue128;" ; cf7 pattern4
cf8 := "\red0\green0\blue128;" ; cf8 pattern5
cf9 := "\red0\green0\blue255;" ; cf9 pattern6
cf10 := "\red0\green128\blue192;" ; cf10 pattern7
cf11 := "\red0\green128\blue255;" ; cf11 pattern8
cf12 := "\red128\green255\blue255;" ; cf12 pattern9
cf13 := "\red0\green128\blue128;" ; cf13 pattern10
Simple save this snippet with an editor of your choice to Whatevername.col and load it from the app. when all went ok, the subpatterns all look in different green tones (hopefully).


; dR's Simple RegEx Tester v 0.2.1
; published 2010 Oct, 22
; http://www.autohotkey.com/forum/viewtopic.php?t=63844
;
; Released under the terms of EUPL 1.1 or later
; See http://www.osor.eu/eupl/european-union-public-licence-eupl-v.1.1
; for a version in your language.
;
; Contrary to aboves licence any commercial utilization or exploitation of
; this tool's sourcecode - even in parts - or in a compiled form is strictly
; prohibited, unless granted in written form by the author of this tool.
; contact SimpleRegExTool [at] itholic [dot] org

AutoExecute:
SetBatchLines,-1
DetectHiddenWindows, On
Process, Exist
pid := ErrorLevel

Gosub, SetDemoText
Gosub, InitVars

Gui,Margin,10,10
Gui,Font,s9,Lucida Console
Gui,Add,Edit,x10 y10 vNeedle w500 hwndRex r3 -WantReturn gInstantChk,% "\b(r\w+[nrst])(?=\s)(.{1,5}\d)?"
Gui,Font
Gui,add,Button,+Default w90 hp yp x+10 gEval vChkBtn, Evaluate
Gui,Font,s9 Ca0a0a0,Lucida Console
Gui,Add,Edit,x10 y+10 w600 vReplacement r2, Replacement
Gui,Font
Gui,Add,GroupBox,w200 r1, Regular Expression Method
Gui,Add,DDL,w180 xp+10 yp+20 vMethod gEval,% RegExReplace( RegExTypes, "\|", "||", any, 1 )
Gui,Add,GroupBox,w390 r1 yp-20 x220 vGroup2, Regular Expression Oprions
Gui,Add,Text,xp+20 yp+20 w28, Start
Gui,Font,s9 Bold cBlack,Lucida Console
Gui,Add,Edit, x+0 yp-3 hp+5 w40 vStartPos gInstantChk, 1
Gui,Font
Gui,Add,Text,x+10 yp+3 w72, ReplaceCount
Gui,Font,s9 Bold cBlack,Lucida Console
Gui,Add,Edit, x+0 yp-3 hp+5 w40 vReplaceCount gInstantChk, -1
Gui,Font
Gui,Add,Text,x+10 yp+3 w78, PCRE Options
Gui,Font,s9 cBlack,Lucida Console
Gui,Add,Edit, x+0 yp-3 hp+5 w75 vOptions gInstantChk, % "i"
Gui,Font
Gui,Add,Tab2,w600 x10 y+20 h420 +0x2C2 vTabs hwndhTabs, RegEx|Colors|Advanced
Gui,Tab,RegEx
Gui, Add, Picture, x+2 y+2 vrPic HwndhWnd
Gui,Tab,Colors
Gui, Add, Picture, x+2 y+2 w30 h365 vrRO HwndhRO
Gui, Add, Button, h30 w255 gCustomColor vCustomColorBtn, Customize that color of your selected text!
Gui, Add, Button, h30 w100 Disabled yp x+5 vColorResetBtn gColorReset, Reset colors!
Gui, Add, Button, h30 w100 Disabled yp x+5 vSaveColorsBtn gSaveColors, Save colors
Gui, Add, Button, h30 w100 yp x+5 vLoadColorsBtn gLoadColors, Load colors
Gui,Tab,Advanced
Gui, Add, CheckBox, x+10 y+10 Checked vShowReplacedText, Show the replaced text as striked through
Gui, Add, CheckBox, xp y+10 Checked vAllowHaystackReplace, Allow RegExReplace to update the Haystack
Gui, Add, CheckBox, xp y+10 vInstantUpdates, % "Update instantly the Haystack with your Regex`n"
. "This might result in a nonworking script. Use carefully!"
Gui,Tab
Gui,Add,StatusBar,+0x100
Gui, Show, +Hide, % "dR's Simple RegExTester v" SRV AHK_VERSION
Gui,+LastFound +Resize +MinSize

; Load RichEdit2 DLL
hInstance := DllCall("LoadLibrary", _Str, "riched20.dll")

ControlStyle := 0x50000000 | 0x200000 | 0x4

; Create Control
REdit := DllCall("CreateWindowEx", _Ptr, 0x200, _Str, RichEdit20, _Str, RichEdit20, _Ptr, ControlStyle ; 0x549371C4
,"int", 10, "int", 40, "int", 530, "int", 410, _Ptr, hWnd, _Ptr, 0, _Ptr, hInstance, _Ptr, 0 )
REdit2 := DllCall("CreateWindowEx", _Ptr, 0x200, _Str, RichEdit20, _Str, RichEdit20, _Ptr, ControlStyle ; 0x549371C4
,"int", 10, "int", 40, "int", 530, "int", 410, _Ptr, hRO, _Ptr, 0, _Ptr, hInstance, _Ptr, 0 )
; EM_LIMITTEXT Message
DllCall("SendMessage", _Ptr, REdit, _Ptr, 0x435, _Ptr, 0, _Ptr, 0x7fffffff )
DllCall("SendMessage", _Ptr, REdit2, _Ptr, 0x435, _Ptr, 0, _Ptr, 0x7fffffff )
; EM_SETTARGETDEVICE - wordwrap
DllCall("SendMessage", _Ptr, REdit, _Ptr, 0x448, _Ptr, 0, _Ptr, 0)
DllCall("SendMessage", _Ptr, REdit2, _Ptr, 0x448, _Ptr, 0, _Ptr, 0)
SetRTF( HayStack )
SetRTF( ColorChooserText, 2 )

ControlMove,,20,197,567,405,ahk_id %REdit%
ControlMove,,20,197,567,370,ahk_id %REdit2%

Eval:
; Select Result Tab
DllCall("SendMessage", _Ptr, hTabs, _Ptr, 0x1330, _Ptr, 0, _Ptr, 0)
Gui,Submit,NoHide

if ( Method == ShowReplace )
Gui,Font,s9 cBlack, Lucida Console
else
Gui,Font,s9 ca0a0a0, Lucida Console
GuiControl,Font,Replacement
if ( StartHaystack == "" || AllowHaystackReplace == 1 )
StartHaystack := GetRTF()
RegExEval()
Return

InstantChk:
GuiControlGet, InstantUpdates
If ( InstantUpdates == 1 )
Gosub, Eval
Return

InitVars:
; Determine the proper name of the control
RichEdit20 := "RichEdit20A"

/*
; below is the version for a real unicode richedit control
; but since it's a real pain working with that e.g.
; keep the text unicode, but all rtf tags in ansi,
; i decided to keep this control in ansi in any case,
; thus sacrifycing the benefits of unicode

RichEdit20 := "RichEdit20" ( A_IsUnicode ? "W" : "A" )
*/

; Set Dflt Values
_Ptr := A_PtrSize ? "Ptr" : "UInt"
_Str := ( InStr( A_AhkVersion, "L" ) ? ( A_IsUnicode ? "W" : "A" ) : "" ) "Str"
CodePage := A_IsUnicode ? 1200 : 0

; SETTEXTEX Structure
VarSetCapacity(SETTEXTEX, 8, 0) ; http://msdn.microsoft.com/en-us/library/bb787954(v=VS.85).aspx
NumPut(1, SETTEXTEX, 0, "Uint") ; (dWord) FLAGS: ST_DEFAULT[=1]
NumPut(CodePage, SETTEXTEX, 4, "Uint") ; (uInt) codepage

Return


SetDemoText:
SRV := "0.2.1" ; Version
colSets := 12
HayStack=
(LTrim Join
Welcome to simple RegExTester %SRV%. It's intended to be a very simple tool, yet power
full enough to easily visualize your RegExNeedles on your custom texts. To do this, si
mply paste in your text in the big box and enter your Regular Expression Needle above
. You will see your results instantly. Features of this tool:`n`n
`t- full regex syntax as it's available to AutoHotkey`n
`t- powerfull colorization including custom colors for named subpatters`n
`t- simple yet powerfull in its usage`n`n
This tool uses a stripped version of corrupt's libraries for RichEdit Controls. The fu
ll libraries and advanced usage samples may be found here:`n`n
`thttp://www.autohotkey.com/forum/viewtopic.php?p=123286#123286`n`n
Beware, the mentioned RTF library is stalled in a very early stage, and might not wor
k as expected. At present day it only uses the RichtEdit v2 Control, thus it cannot b
e run on systems lacking it, such as Windows 95.`n
`nHave fun!`ndR`n
)
ColorChooserText=
(Ltrim Join Comments
This is a Demonstration to show how a regex will be matched. To change that color, sim
ply select the text ( this app checks for keywords ) and click the customize color But
ton. \highlight1 This sentence demonstrates a complete Standard Match\highlight0 , whe
re no other subpatters have been defined. \par `n
Starting with version 0.1.8 subpatterns come into the game.`n
`t\highlight1\b\cf5 This \cf6 long \cf7 sentence \cf8 might \cf9 have \cf10 been \cf1
1 captured \cf12 by \cf13 following \cf14 pattern \cf3\b0\highlight0 .
`n \f1\fs15 U)(\\w+\\.*(\\w+\\.*(\\w+\\.*(\\w+\\.*(\\w+\\.*(\\w+\\.*(
\\w+\\.*(\\w+\\.*(\\w+\\ \f0\fs20 `n`n
As you see there are nine subpatters and aboves sentence is colored individually. Thes
e patterns would have been matched by the AHK RegEx parser as Match1, Match2 .. Match1
0. For now this app takes ten colors as a max. `n`n
This is \strike replaced text\strike0\b\cf4 how it would look like\b0\cf3 , when a re
placement took place.
)
AHK_VERSION := " ( AHK" ( InStr( A_AhkVersion, "L" )
? "_L - Build " A_AhkVersion ( A_IsUnicode ? "-Unicode " : "-ANSI " )
: " Basic " A_AhkVersion )
. " )"
RegExTypes := ( ( ShowMatchPattern := "Show Match Pattern" )
. "|" ( ShowMatchAll := "Show Match All" )
. "|" ( ShowReplace := "Show Replacement" ) )

ColorReset:
cf0 := "\red255\green255\blue255;" ; cf0 default background
cf1 := "\red255\green255\blue164;" ; cf1 hilight matchall
cf2 := "\red128\green128\blue128;" ; cf2 default color
cf3 := "\red128\green0\blue128;" ; cf3 replacement
cf4 := "\red255\green128\blue0;" ; cf4 pattern1
cf5 := "\red128\green0\blue0;" ; cf5 pattern2
cf6 := "\red0\green128\blue0;" ; cf6 pattern3
cf7 := "\red0\green0\blue128;" ; cf7 pattern4
cf8 := "\red255\green0\blue0;" ; cf8 pattern5
cf9 := "\red0\green64\blue0;" ; cf9 pattern6
cf10 := "\red0\green0\blue255;" ; cf10 pattern7
cf11 := "\red255\green0\blue255;" ; cf11 pattern8
cf12 := "\red128\green128\blue0;" ; cf12 pattern9
cf13 := "\red0\green128\blue128;" ; cf13 pattern10

InitBaseRTF:
stdCol := "{\colortbl" ; cf1
. cf0 cf1 cf1 cf2 cf3 cf4 cf5 cf6 cf7 cf8 cf9 cf10 cf11 cf12 cf13
. "}"
cusCol := stdCol
preRTF := "{\rtf1\ud\uc0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;\f1\fswiss\fprq2\fcharset0 Lucida Console;}}"
. cusCol
. "\viewkind4\pard\nowidctlpar\cf3\highlight0\f0\fs20"
postRTF := "\b0\f0\par}"

If ( A_ThisLabel == "ColorReset" ) {
GuiControl, Disable, ColorResetBtn
GuiControl, Disable, SaveColorsBtn
SetRTF( HayStack )
SetRTF( ColorChooserText, 2 )
}
return

GuiSize:
if ( wh && ww ) {
GuiControl, Move, ChkBtn, % "x" A_GuiWidth-100
GuiControl, Move, Tabs, % "w" A_GuiWidth-tabsOw " h" A_GuiHeight-tabsOH
GuiControl, Move, Replacement, % "w" A_GuiWidth-20
ControlGetPos, TabsX, TabsY, TabsW, TabsH,, ahk_id %hTabs%
GuiControl, Move, rPic, % "w" TabsW-30 " h" TabsH-10
ControlGetPos, hPosX, hPosY, hPosW, hPosH,, ahk_id %hWnd%
ControlMove,,hPosX,hPosY,hPosW,hPosH-5,ahk_id %REdit%
GuiControl, Move, rRO, % "w" TabsW-30 " h" TabsH-50
ControlGetPos, hPosX, hPosY, hPosW, hPosH,, ahk_id %hRO%
ControlMove,,hPosX,hPosY,hPosW,hPosH-5,ahk_id %REdit2%
GuiControl, Move, Needle, % "x10 y10 w" A_GuiWidth-120
GuiControl, Move, Group2, % "w" A_GuiWidth-230
GuiControl, Move, CustomColorBtn, % "y" TabsY+hPosH-20 " w" TabsW-345
GuiControl, Move, ColorResetBtn, % "y" TabsY+hPosH-20 " x" TabsW-325
GuiControl, Move, SaveColorsBtn, % "y" TabsY+hPosH-20 " x" TabsW-220
GuiControl, Move, LoadColorsBtn, % "y" TabsY+hPosH-20 " x" TabsW-115
GuiControl, Move, Options, % " w" A_GuiWidth-545
Gui,+LastFound
WinSet, Redraw
} else {
ww := A_GuiWidth, wh := A_GuiHeight
ControlGetPos, TabsX, TabsY, TabsW, TabsH,, ahk_id %hTabs%
tabsOW := ww-TabsW, tabsOH := wh-TabsH
GuiControl, Move, rPic, % "w" TabsW-30 " h" TabsH-10
GuiControl, Move, rRO, % "w" TabsW-30 " h" TabsH-50
}
Return

GuiEscape:
GuiClose:
Esc::
DllCall("DestroyWindow", "Uint", REdit)
DllCall("DestroyWindow", "Uint", REdit2)
DllCall("FreeLibrary", "Uint", hInstance)
ExitApp

CustomColor:
If ( StrLen( Txt := RegExReplace( GetSelRTF(), "^\s*|\s*$" ) ) != 0 )
{
t := "This sentence might have been captured by following pattern", c := 0
if ( RegExMatch( Txt, "\QThis sentence demonstrates a complete Standard Match\E" ) )
c := 1
else if ( RegExMatch( txt, "how it would look like" ) )
c := 3
else if ( InStr( t, txt ) ) {
Loop,Parse,t,%A_Space%
{
if ( RegExMatch( Txt, "\b" A_LoopField "\b" ) )
{
c := 3+A_Index
break
}
}
}
if ( c && RegExMatch( cf%c%, "\D+(\d+)\D+(\d+)\D+(\d+)", col ) ) {
Gui, +LastFound
if ( ( nc := GetColor( (col1<<16)+(col2<<8)+col3 , WinExist() ) ) != -1 )
{
cf%c% := "\red" nc & 255 "\green" ( nc >> 8 ) & 255 "\blue" ( nc >> 16 ) & 255 ";"
Gosub, InitBaseRTF
SetRTF( HayStack ), SetRTF( ColorChooserText, 2 )
GuiControl, Enable, ColorResetBtn
GuiControl, Enable, SaveColorsBtn
}
}
}
Return

LoadColors:
FileSelectFile, FileName, 1, , , RegExTesterColorSet (*.col)
If ( FileName != "" )
{
ColorTable := ""
FileRead, ColorTable, % Filename
loop,Parse,ColorTable,`n,`r
if ( RegExMatch( A_LoopField, "(?P<Name>cf\w+\\s*\:=\s*""(?P<Value>[^""]+)""", Var ) )
%varName% := varValue
Gosub, InitBaseRTF
SetRTF( HayStack ), SetRTF( ColorChooserText, 2 )
GuiControl, Enable, ColorResetBtn
}
Return

SaveColors:
FileSelectFile, FileName, s16, RegExTesterColorSet.col, , RegExTesterColorSet (*.col)
If ( FileName != "" )
{
If ( FileExist( FileName ) )
FileDelete, % FileName
FileAppend,
(LTrim Join`n
cf1 := "%cf1%" ; cf1 hilight matchall
cf3 := "%cf3%" ; cf3 replacement
cf4 := "%cf4%" ; cf4 pattern1
cf5 := "%cf5%" ; cf5 pattern2
cf6 := "%cf6%" ; cf6 pattern3
cf7 := "%cf7%" ; cf7 pattern4
cf8 := "%cf8%" ; cf8 pattern5
cf9 := "%cf9%" ; cf9 pattern6
cf10 := "%cf10%" ; cf10 pattern7
cf11 := "%cf11%" ; cf11 pattern8
cf12 := "%cf12%" ; cf12 pattern9
cf13 := "%cf13%" ; cf13 pattern10
), % FileName
}
Return

; adapted from http://www.autohotkey.com/forum/viewtopic.php?t=17230
; as compiled and written by majkinetor
GetColor( c=0, hGui=0) { ; added in v0.1.7
VarSetCapacity(CHOOSECOLOR,0x24,0), VarSetCapacity(CUSTOM,64,0)
,NumPut(0x24,CHOOSECOLOR, 0),NumPut(hGui,CHOOSECOLOR, 4)
,NumPut(((c&255)<<16)+(c&0xFF00)+((c>>16)&255),CHOOSECOLOR, 12)
,NumPut(&CUSTOM,CHOOSECOLOR, 16),
,NumPut(0x00000103,CHOOSECOLOR, 20)
nRC := DllCall("comdlg32\ChooseColorA", str, CHOOSECOLOR)
return (errorlevel <> 0) || (nRC = 0) ? -1 : NumGet(CHOOSECOLOR, 12)
}

RegExEval(){ ; added in v0.1.7
Global pid, Replacement, StartHaystack, Needle, Method, ShowMatchAll, ShowReplace, ShowMatch
, ShowMatchPattern, ReplaceCount, StartPos, Options, ShowReplacedText, AllowHaystackReplace

; from ListGlobalVars() by Lexikos - http://www.autohotkey.com/forum/post-165430.html#165430
static hwndEdit, pSFW, pSW, bkpSFW, bkpSW

Options := RegExReplace( Options, "i)([^a-z``]|P)" ), Options := Options ( Options != "" ? ")" : "" )
, HayStack := AllowHaystackReplace ? GetRTF() : StartHaystack
, Needle := RegExReplace( Needle, "^[\w``\s]*\)" ), RegExNeedle := Options Needle

if ( StrLen( Needle ) ) {
test := RegExMatch( HayStack, RegExNeedle, Match, StartPos ), RegExErrorLevel := ErrorLevel, p := 0
SB_SetText( "RegEx: " ( RegExErrorLevel != 0 ? RegExErrorLevel : "OK." ) )

if ( test && Method == ShowMatchAll && RegExErrorLevel == 0 )
while ( p := RegExMatch( HayStack, RegExNeedle, CustomMatch, p == 0 ? StartPos : p + StrLen(CustomMatch)+15 ) )
if ( StrLen(CustomMatch) = StrLen(HayStack) || StrLen(CustomMatch) = 0 )
break
else
HayStack := RegExReplace(HayStack, "\Q" CustomMatch "\E", "\b\cf5 " CustomMatch "\b0\cf3 " , o, 1, p)
else if ( test && Method == ShowReplace && RegExErrorLevel == 0 ) {
Chars := "nrt", Chars1 := "`n", Chars2 := "`r", Chars3 := "`t", rc := 0, r := true, p2 := StartPos
Loop,Parse,Chars
Replacement := RegExReplace( Replacement, "(``|\\)" A_loopField, Chars%A_Index% )
While ( ( p1 := RegExMatch( HayStack, RegExNeedle, CustomMatch, p2 ) ) && R )
nr := ( ShowReplacedText == true ? "\strike " CustomMatch "\strike0" : "" ) "\b\cf4 " Replacement
. "\b0\cf3 ", rc += 1, p2 := p1 + StrLen( nr ), HayStack := RegExReplace( HayStack, RegExNeedle, nr
, o, 1, p1 ), R := ( ReplaceCount != -1 ) ? ! ( ReplaceCount > 0 && rc >= ReplaceCount ) : 1
} else if ( Method == ShowMatchPattern && RegExErrorLevel == 0 ) {
RegExMatch( HayStack, RegExNeedle, CustomMatch, StartPos )
; from ListGlobalVars() by Lexikos - http://www.autohotkey.com/forum/post-165430.html#165430
; with a minor fix provided by lexikos to work with ahk_l
if ( !hwndEdit ) {
ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %pid%
hmod := DllCall("GetModuleHandle", "str", "user32.dll"), pSFW := DllCall("GetProcAddress"
, "uint", hmod, "str", "SetForegroundWindow"), pSW := DllCall("GetProcAddress", "uint"
, hmod, InStr( A_AhkVersion, "L" ) ? "astr" : "str" , "ShowWindow"), DllCall("VirtualProtect"
, "uint", pSFW, "uint", 8, "uint" , 0x40, "uint*", 0), DllCall("VirtualProtect", "uint"
, pSW, "uint", 8, "uint", 0x40, "uint*", 0), bkpSFW := NumGet(pSFW+0, 0, "int64")
, bkpSW := NumGet(pSW+0, 0, "int64")
}
NumPut(0x0004C200000001B8, pSFW+0, 0, "int64"), NumPut(0x0008C200000001B8, pSW+0, 0, "int64")
ListVars
NumPut(bkpSFW, pSFW+0, 0, "int64"), NumPut(bkpSW, pSW+0, 0, "int64")
ControlGetText, _text,, ahk_id %hwndEdit%
lst := "", RegExMatch(_text, "sm)(?<=^Local Variables for RegExEval\(\)`r`n-{50}`r`n).*?(?=Global Variables)", _text)
Loop,Parse,_text,`n,`r
If ( RegExMatch( A_LoopField, "^CustomMatch([^:]*)?" ) )
lst .= ( StrLen(Lst) != 0 ? "`n" : "" ) RegExReplace( A_LoopField, "\[\d+ of \d+].*" )
_text := "", n:=1
Sort,lst,U
Loop,Parse,lst,`n
if ( RegExMatch( A_LoopField, "^CustomMatch\d+" ) && ( _n := RegExReplace(A_LoopField,"CustomMatch") ) > n )
n := _n, _n := ""
HayStack := RegExReplace( HayStack, "\Q" CustomMatch "\E", "\highlight1 " CustomMatch "\highlight0 " )
RegExMatch( HayStack, "P" Options ( Options != "" ? "" : ")" ) Needle, CustomMatch, StartPos )
Loop, % n
idx := n+1-A_Index, HayStack := RegExReplace( HayStack, "\Q" CustomMatch%Idx% "\E"
, "\b\cf" idx+4 " " CustomMatch%Idx% "\b0\cf3 ", o, 1, CustomMatchPos%Idx% )
}
}

SetRTF( HayStack )
}

GetSelRTF() { ; added in v 0.1.8
Global REdit2, _Ptr
Static $
if ( ! $ && InStr( A_AhkVersion, "L" ) )
$ := "StrGet"
VarSetCapacity(t, 8, 0), DllCall("SendMessage", _Ptr, REdit2, _Ptr, 0x434, _Ptr, "0", _Ptr, &t)
, VarSetCapacity(t, -1), tbl := NumGet(t, 4, "Int") - NumGet(t, 0, "Int")
If (tbl < 1 )
Return
VarSetCapacity(b, tbl, 0), DllCall("SendMessage", _Ptr, REdit2, _Ptr, 0x43E, _Ptr, "0", _Ptr, &
, VarSetCapacity(b, -1)
return ( A_IsUnicode ) ? %$%( &b, tbl, "CP0") : b
}

GetRTF( re = 1 ){ ; added in v0.1.7 / changed for multiple Ctrls in v0.1.8
Global CodePage, REdit, REdit2

; Get Haystack
VarSetCapacity(t1, 8, 0), t2 := CodePage, VarSetCapacity(t3, 20, 0), NumPut(0, t1, 0), NumPut(t2, t1, 4)
If (ts := DllCall("SendMessage", "UInt", REdit, "UInt", 0x45F, "UInt", &t1, "UInt", "0")) {
ts+=1,ts*=A_IsUnicode ? 2 : 1,NumPut(ts, t3, 0, "Int"), NumPut(t2, t3, 8, "Int"), VarSetCapacity(Haystack, ts + 1, 0)
DllCall("SendMessage", "UInt", re = 2 ? REdit2 : Redit , "UInt", 0x45E, "UInt", &t3, "UInt", &Haystack)
VarSetCapacity(Haystack, -1)
}
return Haystack
}

SetRTF( Haystack, re = 1 ){ ; added in v0.1.7 / changed for multiple Ctrls in v0.1.8
Global preRTF, postRTF, _Ptr, _Str, SETTEXTEX, REdit, REdit2

; Do any neccessary translations
if ( A_IsUnicode )
StrPutVar(preRTF RegExReplace( HayStack, "\r\n|\r|\n", "\par`n" ) postRTF, rtfText, "CP0")
else
rtfText := preRTF RegExReplace( HayStack, "\r\n|\r|\n", "\par`n" ) postRTF
; Set Text
DllCall("SendMessage", _Ptr, re = 2 ? REdit2 : REdit , _Ptr, 0x461, _Ptr, &SETTEXTEX, _Str, rtfText )
Gui Show
}

StrPutVar(string, ByRef var, encoding){ ; added in v0.1.6
static $
if ( ! $ && InStr( A_AhkVersion, "L" ) )
$ := "StrPut"
VarSetCapacity( var, %$%(string, encoding)
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
return %$%(string, &var, encoding)
}


Big fat THX
  • Majkinetor for the base of ColorSelectDlg
  • Lexikos for a small fix in ListGlobalVars so it works with AHK_L
  • Corrupt for doing all that research on RichEdit
  • And to everybody for good suggestions and testing

greets
dR

history:

  • 2010-Oct-23 Update to v0.2.1 changes include minor bugfix and reenabling the instant haystack update
  • 2010-Oct-22 Updated to v0.2.0. changes include positionmodes, replacement, custom colors and a brief UI redesign
  • 2010-Oct-20 Updated to v0.1.6. changes include code improvements, so it runs on AHK_L 32 bit ANSI and Unicode Builds, next to AHK Basic
  • 2010-Oct-19 Fixed minor typo.
  • 2010-Oct-19 Updated to v0.1.5, which hopefully improves the color char rendering, simplified code, added RegEx ErrorLevel, and Gui
  • 2010-Oct-19 Release of v 0.1.0


upcoming features in unordered list:

  • a list with common regex scenarios (eMails, balanced brackets sets, htmltags, urls, codecomments
  • user def history of regexes
  • a list and a former explanations of which option means what
  • a regex trainer (lessons on specific haystacks)
  • mousemenu for that richedit control ( i never missed that one ), thx MEC


feature version list:

  • 0.2.1 Dis/Enabling of the Instant Haystack Update
  • 0.2.0 Starting Position
  • 0.2.0 Outputvar/Subpattern match groups
  • 0.2.0 show match groups
  • 0.2.0 make more options available as chkbox : eg multiline, dotall etc
  • 0.2.0 custom colors
  • 0.2.0 better control of the regexengine such as matchall, simplematch, replace


All scripts, unless otherwise noted, are hereby released under CC-BY

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
Another fine tool from dR;
Thanks!

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
thx. due to stability issues i updated the code and changed the way the hiliting works. hopefully this solved that flickering i got told about.

have fun with version 0.1.5 :)
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
I was very excited to try it out, but it doesn't work for me... I'm running AHK L61H27, Win7. Probably a Unicode incompatibility. If you don't get to it first, I'll try fixing the problem it later in the week.

Any plans to have an "info pane" that'll display specific match groups?

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
Sorry to read that it doesnt work for you. I developed this with AHK Basic under win xp sp3.
i guess the incompability comes from the way the text gets read out of the console. afaik a structure must be set to indicate the proper codepage - in your case unicode. this 'd also affect the way the text gets set back in into the richedit control.

as for other features such as splitting match groups and friends, yes there are plans for that. some milestone ideas:

[*:15vgtbij] show match groups
[*:15vgtbij] make more options available as chkbox : eg multiline, dotall etc
[*:15vgtbij] a list with common regex scenarios (eMails, balanced brackets sets, htmltags, urls, codecomments
[*:15vgtbij] better control of the regexengine such as matchall, simplematch, replace
[*:15vgtbij] user def history of regexes
[*:15vgtbij] a list and a former explanations of which option means what
[*:15vgtbij] a regex trainer (lessons on specific haystacks)
and many more such as
[*:15vgtbij] custom colors
but 1st i want to ensure that the very basics such as getting/setting the haystack, and unicode work rock solid. on 0.1.0 there have been issues with window redraw. hopefully these redraw issues are fixed for now.

if anybody has ideas or usability wishes, let me know.

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
I must say this is quite awesome. I've only found one other free download regex too (regex coach) but it's slow.

great work.

idea: a search box (ctrl+f). that's one thing i miss in things like regexr and regex coach.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
updated to version 0.1.6.

changelog:
[*:34oppg3g] added support for ahk_l 32 bit ( unicode and ansi )
[*:34oppg3g] minor code improvements
have fun
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Very nice dR, great work ;)

:idea: Let user select color.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
You may be interested in: CCChooseColorA() by SKAN

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
What is AHK Basic? I've never heard of it. Is it your custom creation?

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

What is AHK Basic? I've never heard of it. Is it your custom creation?


See <!-- m -->http://www.autohotkey.com/download/<!-- m -->

Installer for AutoHotkey Basic (1.95 MB): This is the original AutoHotkey, suitable for those who don't need Unicode, objects/arrays, and other new features. If you prefer not to run the installer, download this zip file instead.



derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

You may be interested in: CCChooseColorA() by SKAN


i prefer this one instead:
if ( ( c := GetColor( 255, WinExist() ) ) != -1 )
  MsgBox  % "B" ( c >> 16 ) & 255 " G" ( c >> 8 ) & 255 " R" c & 255
return

; adapted from http://www.autohotkey.com/forum/viewtopic.php?t=17230
; as compiled and written by majkinetor
GetColor( c=0, hGui=0) { 
    VarSetCapacity(CHOOSECOLOR,0x24,0), VarSetCapacity(CUSTOM,64,0)
     ,NumPut(0x24,CHOOSECOLOR, 0),NumPut(hGui,CHOOSECOLOR, 4)
     ,NumPut(((c&255)<<16)+(c&0xFF00)+((c>>16)&255),CHOOSECOLOR, 12)
     ,NumPut(&CUSTOM,CHOOSECOLOR, 16), NumPut(0x00000103,CHOOSECOLOR, 20)
    nRC := DllCall("comdlg32\ChooseColorA", str, CHOOSECOLOR)
    return (errorlevel <> 0) || (nRC = 0) ? -1 : NumGet(CHOOSECOLOR, 12) 
}

as its not only shorter, but also works with ahk_l out of the box :)

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Nice function. Thanks, dR!

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Nice and useful work. :)

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

See <!-- m -->http://www.autohotkey.com/download/<!-- m -->

Thanks. So, Chris chose the name Basic?