Search code examples
regexsocketsmirc

Regex mirc situation


Hello i'm having a script but when i try to catch info that i need i cant this is the part of html code that i would like to get:

<div class="pretty-container " >
2100.0
  </div>

So on my socket y try to do this to get the 2100.0(2100.0 it is a variable number):

on *:sockread:foo: {
 var %read
 sockread %read
 if ($regex(%read,<div class="pretty-container " >(.*)<\/div>)) {
    echo -s price founded: $regml(1)
    ; - here i try to catch the 2100.0 number
    sockclose $sockname
 }
}

but this doesn't work i believe it is because the number and are in another line. con some one helpme to solve this please?

thanks in advace,

Carlos


Solution

  • The sockread command you use only reads one line at a time. Seeing as the data you're looking for is spread over multiple lines, your regular expression will never find a match.

    A solution to this would be simply checking whether the current line contains <div class="pretty-container " >, and if so, store the data of the next line in another variable:

      var %read, %number
      sockread %read
      if (<div class="pretty-container " > isin %read) {
        sockread %number
        echo -s Number: %number
        sockclose $sockname
      }