Jump to content
Sign in to follow this  
toonboon

StringRegExp help..

Recommended Posts

toonboon

Hi,

I need help with a regular expression, I have the following bits of text:

Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>
Defence</a></td><tdclass="alL">144</td><tdclass="alL">99</td>
And so on, for all runescape skills

As some of you may see, these are runescape skills, I am building a runescape highscore checker.

now I want to extract the lvl from each, which is the 99 in the coding. I came up with this expression, but it doesn't seem to work.

Stringregexp($source, "Attack</a></td><tdclass="alL">(?: [0-9\,]{0,9})</td><tdclass="alL">(0-9{0,2})</td>")

please help me out.

Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
oMBRa

what's your output should like?

Share this post


Link to post
Share on other sites
toonboon

my output should be the 99 in this case, but can be any number from 1-99


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
oMBRa

#include <Array.au3>
$string = 'Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>' & _
'Defence</a></td><tdclass="alL">144</td><tdclass="alL">99</td>'

$skill = StringRegExp($string, 'alL">([0-9]{2})</td>', 3)
If @error Then
    MsgBox(0, '', @error)
EndIf


_ArrayDisplay($skill)

Share this post


Link to post
Share on other sites
TinyBoy

my output should be the 99 in this case, but can be any number from 1-99

#include <string.au3>
$s='Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>'
$a=_StringBetween($s,">","<")
$result=$a[4]
MsgBox(0, '',$result )

Share this post


Link to post
Share on other sites
oMBRa

#include <string.au3>
$s='Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>'
$a=_StringBetween($s,">","<")
$result=$a[4]
MsgBox(0, '',$result )
with your code, he cant determine where is the value he is searching for in the array

Share this post


Link to post
Share on other sites
toonboon

#include <Array.au3>
 $string = 'Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>' & _
 'Defence</a></td><tdclass="alL">144</td><tdclass="alL">99</td>'
 
 $skill = StringRegExp($string, 'alL">([0-9]{2})</td>', 3)
 If @error Then
     MsgBox(0, '', @error)
 EndIf
 
 
 _ArrayDisplay($skill)
Thank you very much, though it doesn't solve my problem. With this example I can't figure out the skill this belongs to.

I would like to do it in one line,

$attack = StringRegExp($source, "somethingsomethingsomething")
$defence = StringRegExp($source, "somethingsomethingsomething")
Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
oMBRa

so the output should be:

''Attack:99''

''Defence:99'' ?

Share this post


Link to post
Share on other sites
toonboon

no the variable $attack should read 99, but only if the Attack is present..


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
oMBRa

#include <Array.au3>
Global $String = 'Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>' & _
'Defence</a></td><tdclass="alL">144</td><tdclass="alL">98</td>'
Global $Skills


$Attack = StringRegExp($string, '(?i)(Attack|Defence).{0,50}([0-9]{2})</(?i)td>', 3)

If @error Then
    MsgBox(0, '', @error)
EndIf

_ArrayDisplay($Attack)

Edited by oMBra

Share this post


Link to post
Share on other sites
TinyBoy

#include <string.au3>
Local $Attack = "??",$Defence = "??"
$p='([alpha]*)(?:<.*L">)(.*)(?:<.*)'

$s='Attack</a></td><tdclass="alL">252</td><tdclass="alL">99</td>'
Execute(StringRegExpReplace('assign("'&$s,$p,'\1","\2")'))

$s='Defence</a></td><tdclass="alL">144</td><tdclass="alL">66</td>'
Execute(StringRegExpReplace('assign("'&$s,$p,'\1","\2")'))

MsgBox(0, "","Attack: "&$Attack  & @CRLF &"Defence: "&$Defence   )

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  

×