AutoHotkey Community

It is currently May 27th, 2012, 1:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: August 15th, 2008, 12:52 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Thanks for sharing this, I've been meaning to play with RegEx for a while and this makes it much more accessible. :)

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: update?
PostPosted: December 31st, 2008, 3:29 pm 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
with the new ahk being released this excellent program no longer functions correctly, i was wondering if the op was ever going to update this :(

Edit:

It wasnt the new version of ahk, the op updated the script using those kooky ascii characters which threw me in loops. also the matchlist:"Mre_List" is confusing also..


Last edited by Gosugenji on January 1st, 2009, 2:13 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2009, 2:35 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
As far as I can tell, the script works fine with the latest beta. Could you be more specific - i.e. in what way does it malfunction?
pokercurious wrote:
Afaik, the function is magic, and I'm glad that I could harness it's mysterious power.
Thanks for that. :lol: When I read Gosugenji's post, I was expecting ListGlobalVars() was incompatible with the beta, given its low-level nature. This doesn't seem to be the case. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 3:11 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
This script crashes as soon as I input an expression (needle) or a string (haystack). Even if I simply type a in either haystack or needle... boom!

I think either there's something wrong with RegEx parsing in 1.0.48.00 or I'm the unluckiest being on the face of the Earth. :(

Code:
AUTOHOTKEY caused an invalid page fault in
module AUTOHOTKEY.EXE at 018f:0040c26e.
Registers:
EAX=000001b8 CS=018f EIP=0040c26e EFLGS=00010216
EBX=bfc024bb SS=0197 ESP=009bc060 EBP=009bc090
ECX=009bc0f0 DS=0197 ESI=00000000 FS=3d77
EDX=0004c200 ES=0197 EDI=009bc0c0 GS=0000
Bytes at CS:EIP:
89 03 89 53 04 eb 4d 52 8b 54 24 14 6a 01 52 e8
Stack dump:
009bc52c 00000004 009bce9c 009bc090 009bc0f0 00000000 009bc0c0 00000000 00408f5e 009bc090 009bc52c 00000001 bfc024c3 00000000 00000001 00000000

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 11:56 pm 
Drugwash wrote:
This script crashes as soon as I input an expression (needle) or a string (haystack). Even if I simply type a in either haystack or needle... boom!


I don't have any problems with 1.0.0.48 and this script. What operating system are you using? PCRE is still compiled in mbcs mode.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2009, 1:28 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Only using Win98SE. This is odd since I can hardly make AHK crash with a script; with any of mine, at least... :?

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2009, 4:57 am 
Offline

Joined: December 16th, 2007, 12:55 pm
Posts: 48
@Gosugenji

Sorry about that, I just left out some quotes. Fixed now in the first post.

@Drugwash

I'm sorry to hear that the script is causing problems. It works fine for me with 1.0.48 on XP and Vista.

I suppose one thing that you could try is replacing the "©¥®©¥®©¥®©¥®" sequence with something that has more 'standard' characters (e.g. "^&*^&*^&*")- though I can't imagine that that has anything to do with the errors you're getting.

Perhaps someone with more knowledge of the different OS versions can help sort this out.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2009, 6:37 am 
Drugwash wrote:
This script crashes as soon as I input an expression (needle) or a string (haystack). Even if I simply type a in either haystack or needle... boom!

I tried this script when it was 1st posted and had the same problem. If I recall correctly the problem is Lexikos' ListGlobalVars() (not compatible with win98).
I have been using AHK RegEx Tester v2.1 by toralf. I find it works very well on all OS's and is easily modified (like to show hex dump of haystack, initializing the haystack from a dropped file, and a few other personal enhancements). Give it a try! :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2009, 12:35 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Thanks 98er, toralf's script indeed works.

pokercurious: I'll squeeze 'checking Lexicos' function' onto my to-do list but it'll have to wait before getting its turn. It's no biggie, coz I just needed to sort out an issue in a stubborn expression (me being flat noob at RegEx :oops: ) but I eventually made it, after reading some more documentation.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 27th, 2009, 3:43 am 
I used this to make this complex looking regex:

Code:
^\W*((?:[\w \-]|#(?=\d)|(?<=\w)\.|-|(?<=\w) ){5,50}(?:(?<=\w)\.|\w\b))\s*((?:\r?\n|\t|[\^\-\]\\`~!@#$%&*()_+=[{}|;':",./<>?]|\s+)+)\s*(?:\W*((?:[\w \-]|#(?=\d)|(?<=\w)\.|-|(?<=\w) ){3,50}(?:(?<=\w)\.|\w\b))\s*(?:\2|\r?\n|,|\t|[\^\-\]\\`~!@#$%&*()_+=[{}|;':",./<>?]|\s+))?\s*(?:\W*((?:[\w \-]|#(?=\d)|(?<=\w)\.|,|-|(?<=\w) ){3,50}?(?:(?<=\w)\.|\w\b))\s*(?:\2|\r?\n|,|\t|[\^\-\]\\`~!@#$%&*()_+=[{}|;':",./<>?]|\s+))?\s*(\w+|\w+\.?\s*\w+)\s*(?:, |\2|\r?\n|,|\t|[\^\-\]\\`~!@#$%&*()_+=[{}|;':",./<>?]|\s)+\s*\b([A-Z]{2}|\w+|\w+\.?\s*\w+\.?\s*\w*)\b\s*(?:\s+|\2|,|\W)+\s*(\d{5}|[A-Za-z]\d[A-Za-z] ?\d[A-Za-z]\d)


I am attempting here to make a regex that is used to make sense of any address that you throw at it. Any comments/sugguestions are appreciated.[/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 12:18 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I love the script, but it fails when I use the `a option. For example,

Code:
list =
(
AutoHotkey.exe
Lib
REGS
SciTE
XDebugClient
AU3_Spy.exe
AutoHotkey Website
AutoHotkey.chm
)

myVar = AHK

MsgBox % RegExReplace(list, "`am)^(.*)",myVar "\$1")


`n and `r probably don't work either: "ErrorLevel: Compile error 22 at offset 3: unmatched parentheses"

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 28th, 2009, 2:11 pm 
Offline

Joined: October 13th, 2008, 4:14 pm
Posts: 60
Location: South Park, Colorado
dleach wrote:
I am attempting here to make a regex that is used to make sense of any address that you throw at it. Any comments/sugguestions are appreciated.


Explain please. What do you mean by "make sense"? And, what kind of "address"?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Address RegEx
PostPosted: October 29th, 2009, 3:43 am 
What I mean by make sense is basically split out a mailing address with up to
three address "lines". The goal is to do it in a way that should be very acceptive of any format. The regex below is written in a way that chooses delimiters that are more logical first and then resorts to delimiters that are less logical (two or more spaces). This possible because Autohotkey's regex engine appears to be regex directed rather than text directed.

This is what I have now:

^\s*((?:\S{1,20}\x20{1,2}){1,9}?\S{1,20}?)(?:\s*(?:(?:\r?\n)+?|\t+?|,+?|[^\w\s]+?|\s{2,})+\s*)(?:((?:\S{1,20}\x20{1,2}){1,9}?\S{1,20}?)(?:\s*(?:(?:\r?\n)+?|\t+?|,+?|[^\w\s]+?|\s{2,})+\s*)+?)?(?:((?:\S{1,20}\x20{1,2}){1,9}?\S{1,20}?)(?:\s*(?:(?:\r?\n)+?|\t+?|,+?|[^\w\s]+?|\s{2,})\s*)+)?((?:\w{1,20}\.?\x20){0,5}\w{1,20})(?:\s*(?:(?:\r?\n)+?|\t+?|,+?|[^\w\s]+?|\s+)+\s*)([a-zA-Z]{2}|(?:\w{1,20}\x20){0,5}\w{1,20})(?:\s*(?:(?:\r?\n)+?|\t+?|,+?|[^\w\s]+?|\s+)+\s*)(\d{5}|[A-Za-z]\d[A-Za-z][\s-]*\d[A-Za-z]\d)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2012, 10:08 pm 
Offline

Joined: February 17th, 2008, 7:09 am
Posts: 536
Over a few years I've made modifications to this script. Is my updated version even wanted? Here's a screenshot. The big addon is the view on the right, which hopefully not only splits up the RegEx into parts, but editing the right side updates it in the original single line.

Image

The replacement field can accept escaped chars, being `r`n and `t. This way you actually see what you would get from AHK.

EDIT: Oh well. Here's what I have. Hopefully it's good enough for someone else to use if they want to.

Last Update: 10 April 2012

Code:
;Modifications by Era Scarecrow
; 20 March 2012: Added right side for visual breakdown of regex
; 1 April 2012: Added fix for | splitting with escapes. Spaces that can be
;   confused in the right side for indentation now have non-capture groups to
;   tell them apart. Those groups are removed under certain criteria.
; 5 April 2012: Added escape conversions allowing m`n) and others to work
;   properly. Default converts all `r`n`t's to their \r\n\r except for options.
; 10 April 2012: cleaned up regex with anchors. (No functional difference)
;========================+
; Auto-Execution Section |
;==============================================================================
#NoEnv
#SingleInstance force
Sendmode Input

CreateMainGUI()
Return
;==============================================================================


;=========+
; HotKeys |
;==============================================================================
#IfWinActive AHK Regex Sandbox
!c::
   Gui, Submit, NoHide
   clipboard := (tabselection = "RegExMatch") ? mahkcode : rahkcode
return
;==============================================================================


;========================+
; RegExMatch Subroutines |
;==============================================================================
RegExMatchEval:
   Gui, Submit, NoHide
   ; Clear all variables prefixed with "mre_"
   ClearArray("mre_")
   ; Set non-empty defaults
   mstartpos := mstartpos ? mstartpos : 1
   ; Do RegExMatch

   mneedle := regex_escapes_fix(mneedle)
   
   mfoundpos := RegExMatch(mhaystack, mneedle, mre_, mstartpos)
   Gosub, DisplayRegExMatchResults
   Gosub, DisplayRegExMatchCode
   Gosub, DisplayExpandedRegex
return

DisplayRegExMatchResults:
   moutput := "ErrorLevel: " . ErrorLevel . "`n"
           . "FoundPos: " . mfoundpos . "`n"
   mre_list := GetNonEmptyArrayVars("mre_")
   If moutputvar
   {
      Loop, parse, mre_list, `,
      {
         moutput .= moutputvar . Substr(A_LoopField, 5) . ": """ . %A_LoopField% . """`n"
      }
   }
   GuiControl, , mresults, %moutput%
return

DisplayRegExMatchCode:
   StringReplace, mneedle_tmp, mneedle, ", "", All
   mneedle_tmp := regex_escapes_fix(mneedle_tmp, 2)

   regexmatchcode := "FoundPos := RegExMatch(haystack, """ . mneedle_tmp . """"
   If moutputvar
      regexmatchcode .= ", " . moutputvar
   If mstartpos != 1
      regexmatchcode .= (moutputvar ? "" : ", ") . ", " . mstartpos
   regexmatchcode .= ")"
   GuiControl, , mahkcode, %regexmatchcode%
return

RegExMatchNeedleExpanded:
   Gui, Submit, NoHide
   tmp := regexCompact(mneedleExpanded)
   tmp := regex_escapes_fix(tmp, 2)
   GuiControl, , mneedle, %tmp%
return

DisplayExpandedRegex:
   ControlGetFocus, Focused, AHK Regex Sandbox
   if (Focused != "Edit7") {
      mneedle := regex_escapes_fix(mneedle, 2)
       tmp := RegexReFormat(mneedle)
      
       GuiControl, , mneedleExpanded, %tmp%
    }
return
;==============================================================================

;==========================+
; RegExReplace Subroutines |
;==============================================================================
RegExReplaceEval:
   Gui, Submit, NoHide
   ; Set non-empty defaults
   rstartpos := rstartpos ? rstartpos : 1
   rlimit := rlimit ? rlimit : -1
   ; Do RegExReplace
   rneedle := regex_escapes_fix(rneedle)
   
   rep := rreplacementtext
   StringReplace, rep, rep, ``n, `n, All
   StringReplace, rep, rep, ``r, `r, All
   StringReplace, rep, rep, ``t, %a_tab%, All

   rnewstr := RegExReplace(rhaystack, rneedle, rep, rcount, rlimit, rstartpos)
   Gosub, DisplayRegExReplaceResults
   Gosub, DisplayRegExReplaceCode
   Gosub, DisplayExpandedReplaceRegex
return

DisplayRegExReplaceResults:
   routput := "ErrorLevel: " . ErrorLevel . "`n"           
   If routputvar
      routput .= routputvar . ": " . rcount . "`n"
   routput .= "NewStr: " . rnewstr . "`n"
   GuiControl, , rresults, %routput%
return

DisplayRegExReplaceCode:
   StringReplace, rneedle_tmp, rneedle, ", "", All
   rneedle_tmp := regex_escapes_fix(rneedle_tmp, 2)

   regexreplacecode := "NewStr := RegExReplace(haystack, """ . rneedle_tmp . """"
   If (rreplacementtext) or (routputvar) or (rlimit != -1) or (rstartpos != 1)
      regexreplacecode .= ", " . ( rreplacementtext ? """" . rreplacementtext . """" : "" )
   If routputvar or (rlimit != -1) or (rstartpos != 1)
      regexreplacecode .= ", " . ( routputvar ? routputvar : "" )
   If (rlimit != -1) or (rstartpos != 1)
      regexreplacecode .= ", " . ( (rlimit != -1) ? rlimit : "" )
   If (rstartpos != 1)
      regexreplacecode .= ", " . rstartpos
   regexreplacecode .= ")"
   GuiControl, , rahkcode, %regexreplacecode%
return

RegExReplaceNeedleExpanded:
   Gui, Submit, NoHide
   tmp := regexCompact(rneedleExpanded)
   tmp := regex_escapes_fix(tmp, 2)
   GuiControl, , rneedle, %tmp%
return

DisplayExpandedReplaceRegex:
   ControlGetFocus, Focused, AHK Regex Sandbox
   if (Focused != "Edit16") {
      tmp := regex_escapes_fix(rneedle, 2)
       tmp := RegexReFormat(tmp)
      
       GuiControl, , rneedleExpanded, %tmp%
    }
return

;==============================================================================

;========================+
; Array-helper functions |
;==============================================================================
ClearArray(prefix)
{
   global
   lgv := ListGlobalVars()
   Loop, parse, lgv, |
   {
      If (InStr(A_LoopField, prefix) = 1)
         %A_LoopField% = ©¥®©¥®©¥®©¥®
   }
}

GetNonEmptyArrayVars(prefix)
{
   global
   local varlist =
   lgv := ListGlobalVars()
   Loop, parse, lgv, |
   {
      If (InStr(A_LoopField, prefix) = 1) and (%A_LoopField% != "©¥®©¥®©¥®©¥®")
         varlist .= A_LoopField . ","
   }
   StringTrimRight, varlist, varlist, 1
   return varlist
}
;==============================================================================


;===========+
; GUI Stuff |
;==============================================================================
CreateMainGUI()
{
   global
   
   Gui, Add, Tab, x2 y2 w768 h500 +Theme vtabselection -background, RegExMatch|RegExReplace
   
   Gui, Tab, RegExMatch
   Gui, Font
   Gui, Add, Text, x12 y42 w480 h15 +Backgroundtrans, Regular Expression (the "needle"):
   Gui, Add, Text, x12 y97 w235 h15 +Backgroundtrans, Output Variable (defaults to ""):
   Gui, Add, Text, x257 y97 w235 h15 +Backgroundtrans, Starting Position (defaults to 1):
   Gui, Add, Text, x12 y152 w480 h15 +Backgroundtrans, Text to be searched (the "haystack"):
   Gui, Add, Text, x12 y257 w480 h15 +Backgroundtrans, Results:
   Gui, Add, Text, x12 y457 w480 h15 +Backgroundtrans, AHK Code:
   Gui, Font, s10, courier new
   Gui, Add, Edit, x12 y57 w480 h30 -VScroll vmneedle gRegExMatchEval,
   Gui, Add, Edit, x12 y112 w230 h30 -VScroll vmoutputvar gRegExMatchEval, match
   Gui, Add, Edit, x257 y112 w235 h30 -VScroll vmstartpos gRegExMatchEval,
   Gui, Add, Edit, x12 y167 w480 h80 vmhaystack gRegExMatchEval,
   Gui, Add, Edit, x12 y272 w480 h175 vmresults +readonly,
   Gui, Font, s8, courier new
   Gui, Add, Edit, x12 y472 w480 h20 vmahkcode +readonly

   Gui, Add, Edit, x502 y32 w260 h460 vmneedleExpanded gRegExMatchNeedleExpanded,

   Gui, Tab, RegExReplace
   Gui, Font
   Gui, Add, Text, x12 y42 w480 h15 +Backgroundtrans, Regular Expression (the "needle"):
   Gui, Add, Text, x12 y97 w150 h15 +Backgroundtrans, Replacement Text (""):
   Gui, Add, Text, x172 y97 w150 h15 +Backgroundtrans, Output Variable (""):
   Gui, Add, Text, x332 y97 w75 h15 +Backgroundtrans, Limit (-1):
   Gui, Add, Text, x417 y97 w75 h15 +Backgroundtrans, Startpos (1):
   Gui, Add, Text, x12 y152 w480 h15 +Backgroundtrans, Text to be searched (the "haystack"):
   Gui, Add, Text, x12 y257 w480 h15 +Backgroundtrans, Results:
   Gui, Add, Text, x12 y457 w480 h15 +Backgroundtrans, AHK Code:

   Gui, Font, s10, courier new
   Gui, Add, Edit, x12 y57 w480 h30 -VScroll vrneedle gRegExReplaceEval,
   Gui, Add, Edit, x12 y112 w150 h30 -VScroll vrreplacementtext gRegExReplaceEval,
   Gui, Add, Edit, x172 y112 w150 h30 -VScroll vroutputvar gRegExReplaceEval, count
   Gui, Add, Edit, x332 y112 w75 h30 -VScroll vrlimit gRegExReplaceEval,
   Gui, Add, Edit, x417 y112 w75 h30 -VScroll vrstartpos gRegExReplaceEval,
   Gui, Add, Edit, x12 y167 w480 h80 vrhaystack gRegExReplaceEval,
   Gui, Add, Edit, x12 y272 w480 h175 vrresults +readonly,
   Gui, Font, s8, courier new
   Gui, Add, Edit, x12 y472 w480 h20 vrahkcode +readonly

   Gui, Add, Edit, x502 y32 w260 h460 vrneedleExpanded gRegExReplaceNeedleExpanded,

   ; (mostly) generated using SmartGUI Creator 4.0
   Gui, Show, xCenter yCenter h504 w772, AHK Regex Sandbox
}

GuiEscape:
GuiClose:
ExitApp
;==============================================================================


;==================+
; ListGlobalVars() |
; by Lexikos       +====================================+
; http://www.autohotkey.com/forum/viewtopic.php?t=22692 |
;==============================================================================
ListGlobalVars()
{
   static hwnd, hwndEdit, pSFW, pSW, bkpSFW, bkpSW

   if !hwndEdit
   {
      dhw := A_DetectHiddenWindows
      DetectHiddenWindows, On
      Process, Exist
      hwnd := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
      ControlGet, hwndEdit, Hwnd,, Edit1
      DetectHiddenWindows, %dhw%

      hmod := DllCall("GetModuleHandle", "str", "user32.dll")
      pSFW := DllCall("GetProcAddress", "uint", hmod, "str", "SetForegroundWindow")
      pSW := DllCall("GetProcAddress", "uint", hmod, "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")  ; return TRUE
   , NumPut(0x0008C200000001B8, pSW+0, 0, "int64")   ; return TRUE

   , DllCall("SendMessage", "uint", hwnd, "uint", 0x111, "uint", 65407, "uint", 0)

   , NumPut(bkpSFW, pSFW+0, 0, "int64")
   , NumPut(bkpSW, pSW+0, 0, "int64")

   ControlGetText, text,, ahk_id %hwndEdit%

   RegExMatch(text, "sm)(?<=^Global Variables \(alphabetical\)`r`n-{50}`r`n).*", text)
   pos = 1
   Loop {
      pos := RegExMatch(text, "m)^[\w#@$?\[\]]+(?=\[\d+ of \d+\]: )", var, pos)
      if ! pos
            break
      list .= var "|"
      pos += StrLen(var)
   }
   return SubStr(list, 1, -1)
}
;==============================================================================
;added functions by Era Scarecrow

;remove comments and unwanted whitespace, make a neat one-liner.
regexCompact(text){
   text := regexReplace(text, "`amS)\s+##.*+$")
   text := regexReplace(text, "`amS)\s+$")
   text := regexReplace(text, "`amS)^\s+")
   text := regexReplace(text, "[\t\r\n]++")

   ;#convert whitespace non-capture groups to spaces (If it doesn't have a conditional)
   text := regexReplace(text, "\(\?:(\s+([+*?]{0,2}|\{\d*+,?\d*+\}[+?]?))\)", "$1")

   return text
}

regexReFormat(text) {
   global regexFmt
   ;first remove any indentation that might be there, rebuild.
   tmp := regexCompact(text)
   
   ;###Regex ReFormat

   tmp := regexReplace(tmp, "((?<!\\)(\\\\)*+\((?!([^][\\\r\n]*+|\\.)*\])(?:\?(?::|<?[=!]|<\w+>))?)", "`r`n$1`r`n")
   tmp := regexReplace(tmp, "(?<!\\)((?:\\\\)*)(\)((?:\{\d*,?\d\}|[+*?])?[+*?]?)?)(?!([^][\\\r\n]*|\\.)*\])", "$1`r`n$2`r`n")
   tmp := regexReplace(tmp, "(?<!\\)((?:\\\\)*)\|", "$1`r`n|`r`n")
   tmp := regexReplace(tmp, "(?<!\\)((?:\\\\)*)(\[\^?\]?\[?(?:[^][\\\r\n]*+|\\.)*\])", "$1`r`n$2")

   ;#greedy/nongreedy modifiers
   tmp := regexReplace(tmp, "((?<!\\)(\\\\)*(\{\d*+,?\d*+\}[\+\?]?|[\*\+\?][\+\?]?)\+?)(?<!\(\?)(?!([^][\\\r\n]*|\\.)\])", "$1`r`n")

   ;#deal with modifiers
   tmp := regexReplace(tmp, "^([\w``]++)\r?\n\)", "$1)")
   tmp := regexReplace(tmp, "[\r\n]++", "`r`n")

   ;#combine groups that have no length modifiers.
   tmp := regexReplace(tmp, "`am)^(\((?:\?(?:<?[!=]|[:<]))?)[\r\n]*(?!\()((?:[^][\\\r\n*+?]++|\\.)+)[\r\n]*\)", "$1$2)")
   
   ;#deal with leading/trailing spaces. Add into non-capture groups.
   tmp := regexReplace(tmp, "`am)^\(\?:\r?\n( +([+*?]{0,2}|\{\d*+,?\d*+\}[+?]?))\r?\n\)", "(?:$1)")

   tmp := regexReplace(tmp, "`am)^( +(?:[+?*]+|\{\d*+,?\d*+\}[+?]?)?)", "(?:$1)")
   tmp := regexReplace(tmp, "`am)( +)$", "(?:$1)")
   
   ;now for indentation.
   i =
   text =
   loop, parse, tmp, `n, `r
   {
      if (substr(A_LoopField,1,1) = ")")
         i := substr(i, 5)
      
      if (substr(A_LoopField,1,1) = "|")
         text .= substr(i, 5) . A_LoopField . "`r`n"
      else
         text .= i . A_LoopField . "`r`n"
      
      if (subStr(A_loopfield, 1, 1) == "(" && regexMatch(A_LoopField,"^\((.*?)(?<!\\)((\\\\)*\)((?:\{\d*+,?\d*+\}|[+*?])?[+?]?)?)") == 0)
         i .= "    "
   }

   return text
}

;if isNeedle = 1, then it's the actual input regex Match/replace will use
;if isNeedle = 2, as a text version we can use in our source code.
regex_escapes_fix(reg, isNeedle = 1){
   ;bulk convert to escaped chars (normal escaped)
   StringReplace, reg, reg, ``n, \n, All
   StringReplace, reg, reg, ``r, \r, All
   StringReplace, reg, reg, ``a, \a, All
   StringReplace, reg, reg, ``t, \t, All
   
   ;convert raw versions to their escaped equivs
   StringReplace, reg, reg, %a_tab%, \t, All
   StringReplace, reg, reg, `n, \n, All
   StringReplace, reg, reg, `r, \r, All
   StringReplace, reg, reg, `a, \a, All
   
   ;convert escaped to real if it's part of a needle and the 'options'
   if (isNeedle = 1) {
   reg := RegexReplace(reg, "^([^()]*)\\r([^()]*)\)", "$1`r$2)")
   reg := RegexReplace(reg, "^([^()]*)\\n([^()]*)\)", "$1`n$2)")
   reg := RegexReplace(reg, "^([^()]*)\\a([^()]*)\)", "$1`a$2)")
   }

   ;convert escaped (source) if it's part of the options
   if (isNeedle = 2) {
   reg := RegexReplace(reg, "^([^()]*)\\r([^()]*)\)", "$1``r$2)")
   reg := RegexReplace(reg, "^([^()]*)\\n([^()]*)\)", "$1``n$2)")
   reg := RegexReplace(reg, "^([^()]*)\\a([^()]*)\)", "$1``a$2)")
   }

   return reg
}


Last edited by rtcvb32 on April 12th, 2012, 9:56 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2012, 2:14 am 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
rtcvb32 wrote:
Over a few years I've made modifications to this script. Is my updated version even wanted? Here's a screenshot. The big addon is the view on the right, which hopefully not only splits up the RegEx into parts, but editing the right side updates it in the original single line.


thanks a lot, very useful


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group