$matchedtok

By brinxy on Nov 13, 2007

Simple identifier to return all matched tokens in a string separated by a common character.

;;---- $matchedtok : brinxy ----;;
;; About ;;
;; $matchedtok compiles a list of tokens based on matches in a string. ;;
;; You can manipulate this list by using properties to be used like $1 or $2 or $gettok(<string>,N,C) ;;
;; -----------------------------------;;
;; Snippet syntax ;;
;; ------------------------------;;
;; $matchedtok(string,searched token,C)[.prop] ;;
;; To break it down ;;
;;  - string: The string to search for the token..
;;  - searched token: input to be searched in the string 
;;  - C: Common separator 
;;  - [.prop] Similar to $1 and $2 just for the separated tokens. *must be a number*
;; -------------------------------;;
;; Examples: ;;
;;      $matchedtok(this is a string of text,s,32) - returns: "this is string" because those all are tokens with 's' in them. 
;;      $matchedtok(this is a string of text,s,32).1 would return "this" because that is the first match. 
;; Counter Examples ;;
;;      $matchedtok(this is a string of text,s,32).234 returns $false because there is no 234th token. Remember that the property MUST be the Nth token IN the text. 
;;      $matchedtok(this is a string of text,s,32).a returns $false because the property is not a number.
;;      $matchedtok(this is a string of test,s,32).3- returns $false because there are no tokens beyond the third.
;; ------------------------------------;;

alias matchedtok { 
  if ($$1 && $2-3 && $isid) { 
    var %t = $$1, %o  
    while ($findtok(%t,$wildtok(%t,$+(*,$2,*),1,$3),$3)) { 
      %o = $addtok(%o, $gettok(%t,$ifmatch,$3),$3) 
      %t = $deltok(%t,$ifmatch,$3)
    }
    return $iif($prop,$iif($regex($prop,/^([0-9]+)|[-]/gi) && $prop !> $numtok(%o,$3),$gettok(%o,$prop,$3),$false),$iif(%o,%o,$false))
  }
}

Comments

Sign in to comment.
brinxy   -  Nov 14, 2007

Most certainly. But I won\'t change the way I make my comments, used to it by now. And I prefer that way.

 Respond  
guest598594   -  Nov 14, 2007

u can do this for lines and lines of comments in a script

/*
A
Lot
Of
Comments
W/O
;\'s
*/

:)

 Respond  
brinxy   -  Nov 14, 2007

Oh I see.

 Respond  
xDaeMoN   -  Nov 14, 2007

Yeah, I noticed those features which is why I said not bad. ;)

 Respond  
brinxy   -  Nov 13, 2007

Thanks xDaeMoN. But I do believe that mIRC\'s built-in $matchtok will only return one token. Meaning if I used: $matchtok(this is a string,s,1-,32) would only return this. (That\'s what I got when I tested it.) On the contrary, my snippet uses $gettok when retrieving data so you can use things such as 1-. I guess this is just an enhancement to $matchtok.

 Respond  
xDaeMoN   -  Nov 13, 2007

Not bad. But I would stick with the built-in $matchtok. :)

 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.