mIRC Home    About    Download    Register    News    Help

Print Thread
#108731 21/01/05 10:58 PM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
hey there, need help with a regex problem.
i have a string from which i need to get the part where a space occurs between a word and another word (which beings with a *)
ex:

blah blah this_word *another_word

i need to output this_word *another_word, and all other occurences of the pattern. this is what i have so far:

Code:
/regtest {
   var %s = sumthin here*sumthin else *another thing*blah blabber *another occurence
    if ($regex(%s,/([[:space:]]\*.*[[:space:]])/g) > 0) {
      var %regml = 1,%regmsg
      while (%regml <= $regml(0)) {
        %regmsg = $addtok(%regmsg,$regml(%regml),44)
        inc %regml
      }
    }
}


doesn't work quite right tho frown


- I AM -
#108732 21/01/05 11:21 PM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Try this
Code:
  if $regex(%s,/(\S+ \*\S+)/g) {
    var %regml = 1
    while $regml(%regml) {
      %regmsg = $addtok(%regmsg,$v1,44)
      inc %regml
    }
  }

#108733 22/01/05 12:37 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
thnx iori. smile on testing your code iori sir, this was the result:

%s = sumthin here*sumthin else *another thing*blah blabber *another occurence

*another thing*blah blabber *another,blabber *another

the output i was kinda lookin for was sumthin like this:

sumthin here*sumthin else *another thing*blah blabber *anothe occurence

just the parts in color.

im sure you could help me out smile


- I AM -
#108734 22/01/05 12:46 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
That is what it returns smile
Code:
alias rmsg {
  var %s = sumthin here*sumthin else *another thing*blah blabber *another occurence
  if $regex(%s,/(\S+ \*\S+)/g) {
    var %regml = 1
    while $regml(%regml) {
      var %regmsg = $addtok(%regmsg,$v1,44)
      inc %regml
    }
  }
  echo -a %regmsg
}

/rmsg
else *another,blabber *another

#108735 22/01/05 12:57 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
two words for ya Iori:


PER - FECT!

LOL grin

Thnx man, your an absolute genius at this stuff! wink


- I AM -

Link Copied to Clipboard