Regex Buddy

By Sigh_ on Sep 17, 2004

Regex Buddy by Sigh_ (http://xi.ma.cx)

Usage: /rbuddy

You first add strings by right clicking on the side listbox of the first 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.
The second window allows you to view the captured parts of an expression.
It also lets you type in a subtext part to substitute for the matched parts of your selected line

alias rbuddy {
  var %- = echo $rb1 $str(-,35)
  if ($window($rb)) window -c $rb
  if ($window($rb1)) window -c $rb1
  window -Bzedh +Ln $rb1 550 250 300 250 "Courier new" 12
  window -azedl25 +nbt $rb 50 250 500 250 "Courier new" 12
  echo $rb Right click this window to access options, type in the next window for substitutions
  %-
  echo $rb1 Captured: 0
  %-
  %-
  echo $rb1 Substitutions: 0
  %-
  echo $rb1 -
}

alias -l rb return @RegexBuddy
alias -l rb1 return $rb $+ 1

dialog -l rbuddy {
  title "Add strings"
  size -1 -1 260 250
  edit "",1,10 10 240 160, multi return
  check "Evaluate variables/identifiers in input",2,30 175 200 20
  button "Add",3,70 205 50 35
  button "Done",4,140 205 50 35,cancel
}

on *:dialog:rbuddy:sclick:3:{
  filter -ik rbuddy 1 _rb
  $null($input($filtered line $+ $iif($filtered != 1,s) added,iou,Success))
}

alias -l _rb aline -l $rb $($1-,$iif($did(rbuddy,2).state,2,1))

menu @RegexBuddy {
  lbclick:{ 
    rline $rb $line($rb,0) $_regcol($sline($rb,1),$editbox($rb))
    _reglist
  }
  Add strings:dialog -arm rbuddy rbuddy
  Add clipboard contents:{ 
    var %i = 1 
    while (%i <= $cb(0)) {
      if ($cb(%i) != $null) aline -l $rb $ifmatch
      inc %i
    }
  }
  Remove selected:while ($sline($rb,1).ln) dline -l $rb $ifmatch
  Remove all:clear -l $rb
  Hide second window:{ 
    window -h $rb1 
    window -sC $rb -1 -1 720 250
  }
  Show second window:{
    window -a $rb1
    window -a $rb
    window -s $rb 50 250 500 250
  }  
}

on *:input:@RegexBuddy*:halt

on *:keydown:@RegexBuddy*:*:{
  if ($keychar) || ($istok(46 38 40,$keyval,32)) .timer 1 0 rline $rb $line($rb,0) $!_regcol($$sline($rb,1),$editbox($rb)) $(|) _reglist
}

on *:active:@RegexBuddy:{
  if ($rb !isin $lactive) && ($window($rb1).state != hidden) {
    window -a $rb1
    window -a $rb
  }
}

on *:close:@RegexBuddy*:window -c $remtok($rb $rb1,$target,32)

alias _reglist {
  var %i = 1
  while ($line($rb1,0) > 7) dline $rb1 4
  .echo -q $regex($sline($rb,1),$editbox($rb))
  rline $rb1 2 Captured: $regml(0)
  while (%i <= $regml(0)) {
    iline $rb1 $calc($line($rb1,0)-3) %i $+ . $regml(%i) - pos: $regml(%i).pos 
    inc %i
  }
  rline $rb1 $calc($line($rb1,0)-2) Substitutions: $regsub($$sline($rb,1),$editbox($rb),$+(1,$chr(44),08,$editbox($rb1),99,$chr(44),99),%i)
  rline $rb1 $line($rb1,0) %i
}

;; 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 substitutions

alias _regsub {
  var %m,%x = $regsub($1,$2,$3,%m)
  return $iif($prop = n,%x,%m)
}

Comments

Sign in to comment.
napa182   -  Apr 13, 2009

//noop $regex(abc,/([a-z]{1,3})/) | echo -a $regml(1)
it will return abc

 Respond  
randomdude   -  Apr 13, 2009

well it might work for genarel regex, but not for mIRC, at least not this example:

i added line "abc" and typed in the regex "[a-z]{1,3}" and it verifyed it as true

However, when you type it into the regex identifier ( $regex(abc,[a-z]{1,3}) ) the result is 0... that means that the regex does not match the string

too bad :-(

 Respond  
napalm`   -  Oct 05, 2008

www.regexbuddy.com

 Respond  
Yoinx   -  Sep 08, 2006

You input strings of matchtext, then as you input regex, it will show you the parts that match. Its a nice way to learn/check your regex.

 Respond  
Scorpwanna   -  Sep 08, 2006

Is this script suppose to actually do anything? I run it using the instructions provided and all i can do is add a line of text to a list and remove it. That\'s about it.... I figured like, you\'d input a string, and a replacement and click go to show you how it\'s done. But from what I see of this it\'s just another /window.

 Respond  
Pariah   -  Dec 05, 2005

I agree. Great script Sigh_

 Respond  
Yoinx   -  Nov 27, 2005

VERY handy if you\'re just learning regex like I am. Lets you see exactly what you\'re doing.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.