Jump to content

Archived

This topic is now archived and is closed to further replies.

chain

Regex buddy

Recommended Posts

  • Administrators
regex validator, i know how complicated regex's are, so i thought i'd post this as it might be useful for so many regex-haters like myself

 

>;; Regex buddy by Sigh (http://xi.ma.cx);; Usage: /rbuddy;; You first add strings by right clicking on the side listbox of the window;; After strings are added you select one and type a regular expression into the editbox;; As you type it will highlight the matched parts of the selected string;; You can also click on the lines in the listbox to choose a string to handle;; Also includes a couple of aliases (see bottom) that regex users may find handyalias rbuddy {  var %w = @RegexBuddy  if ($window(%w)) window -c %w  window -zedCl35 +bt %w -1 -1 720 150 "Courier new" 12  echo %w Regex buddy by Sigh. Right click the side listbox to begin};; Menu event for options and listbox clicksmenu @RegexBuddy {  lbclick:rline $menu 1 $_regcol($sline($menu,1),$editbox($menu))  Add string:aline -l $menu $$input(Enter a string below,ei,Add a string)  Remove selected:while ($sline($menu,1).ln) dline -l $menu $ifmatch};; Input event to ignore accidental inputson *:input:@RegexBuddy:halt;; Keydown event to call $_regcol and highlight the current stringon *:keydown:@RegexBuddy:*:.timer 1 0 rline $target 1 $!_regcol($$sline($active,1),$editbox($active));; Alias to highlight the part of a string a certain regular expression matches;; $_regcol(string,/exp/)alias _regcol {  .echo -q $regex($2,^(?:m(\C)|(?:(/?)))(?:(?:(\C+)\ $+ $iif(m* iswm $2,1,2) $+ (\C*))|(\C+)))  return $_regsub($1,/( $+ $regml(2) $+ )/ $+ $regml(3),$+(1,$chr(44),08\1,99,$chr(44),99))};; Returns the result of a regular expression substitution rather than the number of substitutions made;; $_regsub(string,/expression/,substring)[.n];; Using the .n property returns what $regsub usually returns, the number of substitutionsalias _regsub {  var %m,%x = $regsub($1,$2,$3,%m)  return $iif($prop = n,%x,%m)}

Link to comment
Share on other sites



×
×
  • Create New...