A portion of my script is acting strangely.

Code:
on *:SOCKREAD:warning: {
  if ($sockerr) {
    echo -detl sockerr
    halt
  }
  else {
    sockread %sockreader
    noop $regex(test1,%sockreader,/<td align="left" valign="top" nowrap><a(.+?) ] <\/td>/gS)
    var %m = 1
    while ($regml(test1,%m)) {
      noop $regex(test2,$regml(test1,%m),/.+nowrap>(.+?)<\/td>.+"top">(.+?)<\/td>/gS)
      var %p = 1
      while ($regml(test2,%p)) {
        inc %p 1
      }
      msg %user $+($chr(40),%m,$chr(41)) Warning was issued $regml(test2,1) for reason $+($chr(34),$regml(test2,2),$chr(34))
      inc %m 1
    }
  }
}


If say, there were 5 instances where the regex will pick up anything, the 4th would be lost, and the counter would restart.

<onijin> (1) Warning was issued 2 months ago for reason "mw"
<onijin> (2) Warning was issued 2 months ago for reason "mw"
<onijin> (3) Warning was issued 2 months ago for reason "mw"
<onijin> (1) Warning was issued 2 months ago for reason "mw"

Upon investigation of the source code received, new lines are being formed where the socket is being started again which interferes with the 4th regex. Even with various testing, I couldn't find a way around this.

What I need help with is changing this snippet into writing the whole request into a txt file, then removing all new lines or other added whitespace that interferes with the regex, and regex the end product.

Any help would be appreciate. Thanks.