Jump to content

StringRegExp


caramen
 Share

Recommended Posts

Hey all,

 

2 questions 

One with a problem of knowledge. 

One with how to improve myself on regexp

@mikell You're welcome :)

This is a reproducer that you can run> i want to ping 5 servers and return the response in a label.

#include <Constants.au3>
#include <Array.au3>



  $Ping1 = "escs001"
 Local $cDisk = Run(@ComSpec & " /c ping "&$Ping1 , @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
 Global $cData = ""
      While 1
        $line = StdoutRead($cDisk)
        If @error Then ExitLoop
        $cData &= $line
      WEnd

$cSplitedData = StringSplit ($cData,@CRLF)
MsgBox(0,"",$cSplitedData[5])
    $aArray = StringRegExp(''&$cSplitedData[5], '(?i)temps=(..?)', $STR_REGEXPARRAYMATCH, 1)
    If @error Then Exit
    $iOffset = @extended
    For $i = 0 To UBound($aArray) - 1
        MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 1 - " & $i, $aArray[$i])
    Next

Well I am done with it but not totaly. 

With that regexp the return value is : 11 or 15 or 115 depend of the time response 

How could i do to get 11 ms or 15 ms or 115 ms??

Btw i forgo to add the return of comspec it can be:

R,ponse de 10.2.0.200ÿ: octets=32 temps=12 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=1 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=13 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=12 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=25 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=20 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=112 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=1 ms TTL=126
R,ponse de 10.2.0.200ÿ: octets=32 temps=18 ms TTL=126

 I know i can solve my "problem" the simplest way by adding a second label with "ms" string and I will be done. 

But in my long AutoIT way I prefer to learn how to arrive to my goal with the best way :D 

How to improve myself with that StringRegExp ??

Becose actually i dont realy know what i am doing by using all these parameters...  How to practice it ?!

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Wait i just tryed this and it work @mikell or anyother string regexp pro can confirm it s a good syntax :D

 

(?i)temps=(.. ms)

It is frustrating to guess about not being able to make a stringregexp script without help :/

 

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Ah ok thank you ! 

@Nine I said ok without testing but after testing all my stringregexp return @error now. 

 

Anytips to improve myself anyone ?

 

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@Nine

What a biuty... 

 

You earned a thanks ;) 

image.png.b0dc898eab33c6a8903294548fa526e7.png

 

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

regex101 is awesome I posted it all the time, and you can even link an example.

It looks like temps is static, and I am assuming ms is static so any of the last couple of examples is good.

Does it stay as ms if its over 1000? if not I would probably target TTL as the next static term so you capture anything between and strip white space as needed.

https://regex101.com/r/5z0ncw/1

$sString = "octests=32 temps=12342134233 ms TTL=126"
$sRegExPattern = "temps=(.*)TTL"
$aResult = StringRegExp($sString, $sRegExPattern, 1)
If IsArray($aResult) Then
    $sFinalResult = StringStripWS($aResult[0], 8)
    MsgBox(0, "", $sFinalResult)
EndIf

 

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...