Jump to content

Help With A Little RegExp


 Share

Recommended Posts

So I'm gathering some data from a Wiki and everything was going well but I've hit a road block. I know how to use StringRegExp when there's only 1 variable to the string. But with multiple types I'm not sure how to work it.

 

This is my full script atm.

 

#include <array.au3>

HotKeySet("{`}", "_Run")

Global $URL, $sSource, $ItemName, $ItemStats, $ItemImg, $Lvl, $Stats, $DataField1

Global $ItemData[500], $ItemsNames[500], $ItemUrls[500], $ItemsStats[500]

Global $ItemLog = @ScriptDir & "/ItemLog.txt"

Func _Run()
   MsgBox(0, "Logging", "Starting Log")
    $URL = ClipGet()
    $sSource = BinaryToString(InetRead($URL))
    $ItemData = StringRegExp($sSource,'(?i)(?s)<span style="color: #A59263; font-size: 1.4em; letter-spacing: .15em; margin: .25em; font-family: Georgia;">(.*?)</span></p></span></td></tr></table></div>',3)
    For $i = 0 To UBound($ItemData) - 1
       $ItemName = StringSplit($ItemData[$i], '<', 0)
       $ItemsNames[$i] = '"name: "' & $ItemName[1] & '",'


       $ItemImg = StringSplit($ItemData[$i], 'https://d1u5p3l4wpay3k.cloudfront.net/diablo_gamepedia', 1)
       $ItemImg = StringSplit($ItemImg[2], '"', 0)
       $ItemUrls[$i] = '"url": "https://d1u5p3l4wpay3k.cloudfront.net/diablo_gamepedia' & $ItemImg[1]

      $ItemStats = StringSplit($ItemData[$i], 'style="color: #CCCCCC; font-size: .9em;">', 1)
      $SplitData = StringSplit($ItemStats[2], ":",1)
      $DataField1 = $SplitData[1]
      ClipPut($ItemStats[2])
      MsgBOx(0, "Test", "Wait")
      $SplitData = StringRegExp($ItemStats[2], '(?i)(?s)<span style="(.*?)</span>', 3)
      For $a = 0 To UBound($SplitData) - 1
         MsgBox(0, "Test", $SplitData[$a])
      Next

      ; $ItemStats = StringRegExp($ItemData[$i], '(?i)(?s)<span style="color: #4169E1;">(.*?)</span>',3)
Next

EndFunc

While 1
    Sleep(10)
WEnd

So the section I am trying to pull is this;

 

2H Damage: <span style="color: #4169E1;">(5-6) to (39-52)</span><br />Attack Speed: <span style="color: #CCCCCC;">[10]</span><br />Minimum Strength: <span style="color: #CCCCCC;">50</span><br />Minimum Dexterity: <span style="color: #CCCCCC;">65</span><br />Level Requirement: 28<br /><br /><span style="color: #4169E1;">+70-130% Enhanced Damage (varies)</span><br /><span style="color: #4169E1;">+1 to Amazon Skill Levels</span><br /><span style="color: #4169E1;">3% Mana Stolen per Hit</span><br /><span style="color: #4169E1;">+5 to Strength</span><br /><span style="color: #4169E1;">+2 to Exploding Arrow (Amazon Only)</span><p><br /><span style="color: #4169E1;">(Only Spawns In Patch 1.09 or later)

 

So I need it to pull all the various stats IE;

 

2H Damage: (5-6) to (39-52)

Attack Speed: [10]

Minimum Strength: 50

 

Ect. ect.

 

I'm not quite sure what the best way to go about this is. 

 

I was going to use StringSplit's ect. ect. but with all the different types of stats I'm not quite sure what the best way to attack it is.

 

Thanks!

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

To make the thing easier I suggest to do it in 2 steps

#Include <Array.au3>

$s = '2H Damage: <span style="color: #4169E1;">(5-6) to (39-52)</span><br />Attack Speed: <span style="color: #CCCCCC;">[10]</span><br />Minimum Strength: <span style="color: #CCCCCC;">50</span><br />Minimum Dexterity: <span style="color: #CCCCCC;">65</span><br />Level Requirement: 28<br /><br /><span style="color: #4169E1;">+70-130% Enhanced Damage (varies)</span><br /><span style="color: #4169E1;">+1 to Amazon Skill Levels</span><br /><span style="color: #4169E1;">3% Mana Stolen per Hit</span><br /><span style="color: #4169E1;">+5 to Strength</span><br /><span style="color: #4169E1;">+2 to Exploding Arrow (Amazon Only)</span><p><br /><span style="color: #4169E1;">(Only Spawns In Patch 1.09 or later)'

$s = StringRegExpReplace($s, '(?s)<span.*?>', "")
;Msgbox(0,"", $s)

$res = StringRegExp($s, '(?|2H Damage|Attack Speed|Minimum Strength)[^<]+', 3)

_ArrayDisplay($res)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...