Sign in to follow this  
Followers 0
Allow2010

need help for some regex code..

3 posts in this topic

#1 ·  Posted (edited)

Hello,

i have some html code and i need to extract some information from this code. I tried using StringRegExp, but i am not very good at this.

I hope someone might be willing to help me out:

<tr><td class="iconrow led_green" datalabel="1111"></td><td title="">1111</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*111#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:0" name="edit" value="msn:0" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:0" name="delete" value="msn:0" title="Loeschen" onclick="return delConfirmation('1111')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1212"></td><td title="">1212</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*112#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:1" name="edit" value="msn:1" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:1" name="delete" value="msn:1" title="Loeschen" onclick="return delConfirmation('1212')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1313"></td><td title="">1313</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*113#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:2" name="edit" value="msn:2" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:2" name="delete" value="msn:2" title="Loeschen" onclick="return delConfirmation('1313')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1414"></td><td title="">1414</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*114#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:3" name="edit" value="msn:3" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:3" name="delete" value="msn:3" title="Loeschen" onclick="return delConfirmation('1414')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1515"></td><td title="">1515</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*115#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:4" name="edit" value="msn:4" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:4" name="delete" value="msn:4" title="Loeschen" onclick="return delConfirmation('1515')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1616"></td><td title="">1616</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*116#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:5" name="edit" value="msn:5" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:5" name="delete" value="msn:5" title="Loeschen" onclick="return delConfirmation('1616')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1717"></td><td title="">1717</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*117#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:6" name="edit" value="msn:6" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:6" name="delete" value="msn:6" title="Loeschen" onclick="return delConfirmation('1717')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1818"></td><td title="">1818</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*118#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:7" name="edit" value="msn:7" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:7" name="delete" value="msn:7" title="Loeschen" onclick="return delConfirmation('1818')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1919"></td><td title="">1919</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*119#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:8" name="edit" value="msn:8" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:8" name="delete" value="msn:8" title="Loeschen" onclick="return delConfirmation('1919')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr><tr><td class="iconrow led_green" datalabel="1010"></td><td title="">1010</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*110#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:9" name="edit" value="msn:9" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:9" name="delete" value="msn:9" title="Loeschen" onclick="return delConfirmation('1010')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>
</tr>

This code shows telephone numbers (in the example 1111,1212,1313...1010). In the line that has the number there is something like "edit_msn:X". (X=0-9).

I need to find a way to get a list/array so that i can find the number for msn:0 is 1111, msn:1 is 1212 and so on...

here is what i got so far:

#include <Array.au3>

$htmlcode = '<td class="iconrow led_green" datalabel="1111"></td><td title="">1111</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*111#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:0" name="edit" value="msn:0" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:0" name="delete" value="msn:0" title="Loeschen" onclick="return delConfirmation(' & "'1111'" & ')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>'

$aReturn = StringRegExp($htmlcode, '<td class="iconrow led_green" datalabel="(\d+)', 3)

_ArrayDisplay($aReturn)

The Problem here is that i need to make sure i get the right number for msn:X and also to make sure i get the results for all msns

Can anyone please guide me how to do that?

Thanks !

 

Edited by Allow2010

Share this post


Link to post
Share on other sites



Try this.

#include <Array.au3>

$htmlcode = '<tr><td class="iconrow led_green" datalabel="1111"></td><td title="">1111</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*111#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:0" name="edit" value="msn:0" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:0" name="delete" value="msn:0" title="Loeschen" onclick="return delConfirmation(''1111'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1212"></td><td title="">1212</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*112#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:1" name="edit" value="msn:1" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:1" name="delete" value="msn:1" title="Loeschen" onclick="return delConfirmation(''1212'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1313"></td><td title="">1313</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*113#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:2" name="edit" value="msn:2" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:2" name="delete" value="msn:2" title="Loeschen" onclick="return delConfirmation(''1313'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1414"></td><td title="">1414</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*114#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:3" name="edit" value="msn:3" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:3" name="delete" value="msn:3" title="Loeschen" onclick="return delConfirmation(''1414'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1515"></td><td title="">1515</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*115#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:4" name="edit" value="msn:4" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:4" name="delete" value="msn:4" title="Loeschen" onclick="return delConfirmation(''1515'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1616"></td><td title="">1616</td><td datalabel="Anschluss">Festnetz</td><td datalabel="Anbieter"></td><td datalabel="Vorauswahl">*116#</td><td class="btncolumn" datalabel=""><button type="submit" class="icon" id="edit_msn:5" name="edit" value="msn:5" title="Bearbeiten"><img src="/css/default/images/bearbeiten.gif" alt="Bearbeiten"/></button><button type="submit" class="icon" id="delete_msn:5" name="delete" value="msn:5" title="Loeschen" onclick="return delConfirmation(''1616'')"><img src="/css/default/images/loeschen.gif" alt="Loeschen"/></button></td>' & _
        '</tr><tr><td class="iconrow led_green" datalabel="1717"></td><td title="">1717</td><td'

$aReturn = StringRegExp($htmlcode, '(?:\Q"iconrow led_green" datalabel="\E(\d+).+?\Qedit_msn:\E(\d+))', 3)
;_ArrayDisplay($aReturn, "1D Array")

Local $aReturn2D[UBound($aReturn) / 2][2]
For $i = 0 To UBound($aReturn2D) - 1
    $aReturn2D[$i][1] = $aReturn[$i * 2]
    $aReturn2D[$i][0] = $aReturn[($i * 2) + 1]
Next

_ArrayDisplay($aReturn2D, "2D Array", 0, "", "|", "msn|Number")

 

Share this post


Link to post
Share on other sites

thanks a lot, i did not see your reply, so i will try this out today...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0