mIRC Home    About    Download    Register    News    Help

Print Thread
regex with binvar #260478 27/04/17 03:28 PM
Joined: Jul 2006
Posts: 3,664
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,664
While this may have been suggested in the past, I don't think it was pointed out why this is needed.
One simple example which pushed me to write this: the default mIRC tool for log file does not allow me to search via regex, I could suggest for it here but in the meantime I still need the functionality.
My log files are much bigger than 4150 characters, of course (so $regex is not an option).
You must be thinking, why I am not using /filter, for example, well that leads to the problem, how do I correctly search multiple line at once? I simply cannot.
Concrete example: I want to find someone saying 'hash table' in my log, but only when the next line contains, let's say 'efficiency'.
In PCRE that's about using:

/^TIMESTAMP NICK .*?hash table.*\nTIMESTAMP NICK .*?efficiency/s

Where TIMESTAMP and NICK handle the format for my timestamp and nick decoration.
Of course it's possible to workaround this, calling /filter -nk to find the first line and then check that the next line has what we want (would probably needs a $read call inside the custom alias called by /filter, this is terrible!)
I also think this is long overdue, I don't see why that wasn't added before.

I was thinking about improving $bfind in this regard, $bfind(&bvar,pattern) seems fine, if pattern is only a number then users can use delimiters, which shouldn't break script.

However this is only good for searching, I suppose replacing would also be great.

$breplace(&binvar,a,o,more,replacement) - no regex replacement, would be equivalent to /breplace but works with string
$breplace(&binvar,/(a)(.)/g,o \n \1).regex - regex replacement, behave the same as $regsubex with its new behavior regarding $regsub: returns the number of replacement made since returning the &binvar wouldn't be useful.

$breplacex would also be a thing, then.

These are just quick idea/syntax I came up with, it could be different as long as the functionality is there.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: regex with binvar [Re: Wims] #261729 20/11/17 12:05 AM
Joined: Aug 2016
Posts: 49
R
rockcavera Offline
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2016
Posts: 49
It would be very interesting to have an identifier that would work with &binvar as input and regex to work with that input, not only for replacement, but also for search, since $bfind does not work with &binvar as input.


rockcavera
#Scripts @ irc.VirtuaLife.com.br
Re: regex with binvar [Re: rockcavera] #261730 20/11/17 11:07 AM
Joined: Jul 2006
Posts: 3,664
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,664
Thanks for the support!
Quote:
since $bfind does not work with &binvar as input
$bfind does support binvar as input

Last edited by Wims; 20/11/17 02:50 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: regex with binvar [Re: Wims] #261731 20/11/17 08:43 PM
Joined: Aug 2016
Posts: 49
R
rockcavera Offline
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2016
Posts: 49
Thanks for correcting me, Wims.

Actually I wanted to mention that $bfind does not work with regex.

Disregard the final part "... since $bfind does not work with &binvar as input."


rockcavera
#Scripts @ irc.VirtuaLife.com.br
Re: regex with binvar [Re: Wims] #261929 15/12/17 03:26 AM
Joined: Jun 2008
Posts: 6
D
digitok Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2008
Posts: 6
I also support this idea.

Re: regex with binvar [Re: Wims] #261944 15/12/17 04:42 PM
Joined: Jul 2013
Posts: 26
K
kikuchi Offline
Ameglian cow
Offline
Ameglian cow
K
Joined: Jul 2013
Posts: 26
I also support this suggestion.

Re: regex with binvar [Re: Wims] #266720 21/01/20 01:08 PM
Joined: Apr 2010
Posts: 939
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 939
Bumping this thread as Im in need of this feature


I'm currently working on an HTTP implementation. Within that implementation I need to verify header values are formatted correctly; A header's value is stored in a bvar and can be over the ~8k string-length limit imposed.

I need to check if the header's value only contains values in the ASCII range(1-126). Currently this requires a (slow) loop for what amounts to a OR check of values:
Code
alias isAscii {
  if (!$bvar($1, 0)) {
    return $false
  }

  var %x = 1, %len = $bvar($1, 0)
  while (%x < %len) {
    inc %x
    if ($bvar($1, %x) == 0 || $v1 > 126) {
      return $false
    }
  }

  return $true
}




To amend Wim's suggestion what I'd like to see is:
Code
$bfind(&binvar, start-position, [end-position], [name], pattern).regex
  Returns the starting position of the first found match

  &binvar
    The bvar to search

  start-position
    The starting position of which the search should begin
    Must be an integer value

  end-position - Optional
    The end position of which the search should stop
    Must be an integer value

  name - Optional
    The regex-name to use when referencing the match list via $regml()
    Must not be a numerical value

  pattern
    The regex pattern

  .regex
    Indicates a regex pattern has been specified


$breplace(&binvar, substring, newstring...)
$breplace(&binvar, substring, newstring...).cs
  Performs a text-based in-place substitution  on a binary variable
  Returns the number of substitutions made

  if .cs is specified, the search will be case-sensitive


$breplace([name], &binvar, pattern, subtext).regex
  Performs a regex-based in-place substitution on a binary variable
  Returns the number of substitutions made

  You can assign a name to a $breplace().regex call which you can use later in $regml() to retrieve the list of matches.


$regml([name], n, [&binvar])
$regmlex([name], m, n, [&binvar])
    Similar to the current implementation except the result is output to the specified &binvar
    If outputting to a &binvar, the length of the bvar is returned



The reason I have choosen a new identifier over altering $replace/cs and $regsubex is that of the end-result differing. With current implementations, the replace creates a new string and once substitutions have finished, the new string is returned. The functionality I'd like to see is that of substitutions being performed in-place

Last edited by FroggieDaFrog; 21/01/20 02:30 PM.

I am SReject
My Stuff