jmp Posted October 28, 2019 Posted October 28, 2019 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)
FrancescoDiMuro Posted October 28, 2019 Posted October 28, 2019 @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: Forum Rules Forum Etiquette
mikell Posted October 28, 2019 Posted October 28, 2019 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) FrancescoDiMuro 1
FrancescoDiMuro Posted October 28, 2019 Posted October 28, 2019 @mikell I meant to write it like this: ConsoleWrite(StringRegExp($oTd.InnerText, "[^:]+\h*:\h*(\d{3,4})\h*\(", $STR_REGEXPARRAYMATCH)[0] & @CRLF) 2 minutes ago, mikell said: (monday morning is painful) You're definitely right! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
jmp Posted November 23, 2019 Author Posted November 23, 2019 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now