mIRC Homepage
Posted By: Raccoon New $regex() command parameter. - 13/10/18 08:32 PM
I would like to propose a new command parameter for $regex(), like so:

$regex(name, string, pattern, command)

Thus allowing for clever handling of match strings or capture groups.

Examples: The command parameter could be used to /hadd a series of <key> <data> fields to a hash table from JSON or XML outputs. It can be used to easily break up a string of switch parameters into a series of correctly named %variables. It would add a level of convenience for handling long and complex lists without the need for building while loop, and nested while loop constructs.

Command parameters are one of the more interesting aspects of this language. smile

<Cue the Wims!>
Posted By: Wims Re: New $regex() command parameter. - 13/10/18 11:05 PM
Nice suggestion smirk
Posted By: Raccoon Re: New $regex() command parameter. - 28/02/19 08:21 PM
bump cool

Code:
RAW 005:*: { ; ISUPPORT
  var %table = session
  noop $regex(isupport, $3-, /(?:\s:.*)|(\S+)/g, hadd -m %table $+(isupport.,$cid,.,\n) $$+(\1)) (or $$1)
}
Posted By: kap Re: New $regex() command parameter. - 01/03/19 10:12 AM
Hello Raccoon,

Can you please breakdown your regex with an example line so I may understand better what it does?

Kind regards
Posted By: Raccoon Re: New $regex() command parameter. - 02/03/19 05:09 AM
Sorry kap, it was slightly broken.

The idea being to capture space delimited tokens, but ignore everything following a space and a colon. Turns out that $1- eliminates the colon, so I had to switch to $rawmsg instead of $1-. It was just written freehand as an example, untested.
© mIRC Discussion Forums