$stripwm

By Mpdreamz on Jun 23, 2006

Syntax: $stripwm(text,wildmatch).[frN]

text: is the text you wish to strip.

wildmatch: the wildmatch you wish to strip. The wildmatch character is "" (without the quotes).
"a
d" will match "abcdefg" but also "1234abcdefg"
so unlike wildmatching ON TEXT "ad" means a followed by zero or more characters up to the last d it finds anywhere in the string
and not a string that starts with a followed by 1 or more characters followed by a d.
therefor the match "a
" will completely strip the text "abcdefg"

Properties:
-f : this makes stop at the First character it finds after instead of the last
//echo -a$stripwm(aq hello aq,aq).f
returns "hello" instead of stripping the entire text.
-rN : makes it strip everything but the matches it makes and returns a tokenized list of all the matches.
//echo -a$stripwm(aq hello aq hello arghq,a
q).fr
returns "aq,aq,arghq"
//echo -a $stripwm(aq hello aq hello arghq,a*q).r
returns "aq hello aq hello arghq"

N stands for the ascii delimiter for the return tokens
//echo -a $stripwm(aq hello aq hello arghq,a*q).fr46
returns "aq.aq.arghq"

if not specified it will use $chr(44) (,) by default.

In short

  • means zero or more characters ! "h*e" matches "hello".
  • matches the longest possible match unless you specify the .f property then it will match the shortest
    .rN makes it strip everything BUT the match you specify returning a tokenized list of all the values it didnt strip.
    Where N is an optional property for the ascii value of the delimiter.
alias stripwm { 
  if ((!$1) || (!$2)) || (!$isid) return 
  var %r = $+(/,$chr(40),$regsubex($regsubex($regsubex($regsubex($2,/(\.|\?|\+|\[|\]|\^|\$|\\)/g,\\t),/\*$/,*$),/^\*/,^*),/\*/g,$+(.*,$iif(f isin $prop,?))),$chr(41),/g)
  if (r isin $prop) { 
    var %t = $regex(stripwm,$1,%r) , %m = $regml(stripwm,0) , %x = 1 , %return
    while (%x <= %m) {
      %return = $instok(%return,$regml(stripwm,%x),%x,$iif($regsubex($prop,/\D/g,),$v1,44))
      inc %x
    }
    return %return
  }
  return $regsubex($1,$+(%r,g),)
}

Comments

Sign in to comment.
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.