Jump to content

Recommended Posts

i am trying to get number from string using this code :

#include <IE.au3>
$oIE = _IEAttach ("Edu.corner")
Local $aName = "Student name & Code:", $iaName = "0"
Local $oTds = _IETagNameGetCollection($oIE, "td")
For $oTd In $oTds
    If $oTd.InnerText = $aName Then
        $iaName = $oTd.NextElementSibling.InnerText
        $iGet = StringRegExpReplace($iaName, "\D", "")
     EndIf
Next
MsgBox(0, "", $iGet)

it was get number like 52503058

But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

area.JPG.fff7ca29de5bc44876cf45439e8e962b.JPG
 

Link to comment
Share on other sites

@jmp

You could use something like this:

ConsoleWrite(StringRegExp($oTd.InnerText, "[^:]+\h*:\h*(\d{3,4})\h*\(", $STR_REGEXPARRAYMATCH) & @CRLF)

By the way, what kind of sense do those variables names have?

$aName is not an array (the "a" should stand for array), and $iGet is not supposed to contain an integer value (the "i" should stand for integer), but a string.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • 4 weeks later...
On 10/28/2019 at 1:08 PM, mikell said:

If this 3 or 4 digits number is the first one encountered inside the <td> then this may work

$Text = "ab 6 c 1234 def 5678 ghi"
Msgbox (0, "", StringRegExpReplace($Text, '.*?(\d{3,4}).*', "$1") )

@FrancescoDiMuro
$STR_REGEXPARRAYMATCH returns an array  (monday morning is painful) :)

@mikell Thank you very much. you are great.

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

×
×
  • Create New...