jcpetu Posted November 24, 2018 Share Posted November 24, 2018 Hi there, I'm trying to create a little script using StringRegExp to filter the interface connection status, but I can't make the appropriate expression to filter letters with tilde in spanish. This is what I have by now: #include <Array.au3> #include <constants.au3> Local $interface = Run("netsh interface show interface wi-fi", "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($interface) If @error Then ExitLoop WEnd ConsoleWrite($output & @CRLF) $Status = StringRegExp($output, "(?m).+\hEstado de conexión+\h+\h+(.*)\s", 3) If Not @error Then ConsoleWrite("Status: " & $Status & @CRLF) Any help will be appreciated! Link to comment Share on other sites More sharing options...
jchd Posted November 25, 2018 Share Posted November 25, 2018 Post subject and expected result strings. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jcpetu Posted November 25, 2018 Author Share Posted November 25, 2018 Hi jchd, when running netsh interface show interface wi-fi you get: Wi-Fi Tipo: Dedicado Estado administrativo: Habilitado Estado de conexión: Conectado And I'm using StringRegExp to extract: Conectado The code I corrected is: #include <Array.au3> #include <constants.au3> Local $interface = Run("netsh interface show interface wi-fi", "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($interface) If @error Then ExitLoop WEnd ConsoleWrite($output & @CRLF) $Status = StringRegExp($output, "(?m).+\hEstado de conexión+\h+\h+(.*)\s", 3) _ArrayDisplay($Status ) If Not @error Then ConsoleWrite("Status: " & $Status[0] & @CRLF) Link to comment Share on other sites More sharing options...
Developers Jos Posted November 25, 2018 Developers Share Posted November 25, 2018 Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mikell Posted November 25, 2018 Share Posted November 25, 2018 No problem with spanish letters, There were some errors in the pattern Please try this $status = StringRegExpReplace($output, "(?s).+Estado de conexión:\h+(\w+).*", "$1") Link to comment Share on other sites More sharing options...
jcpetu Posted November 25, 2018 Author Share Posted November 25, 2018 Hi mikel, thls for your help. It doesn't work. It doesn't output anything. I would like to get the result in an array to been able to use it in a list view where I would like to show the connection status for different interfaces. For example, if I use this little piece of code I got an array with the result: #include <Array.au3> #include <constants.au3> Local $interface = Run("netsh interface show interface wi-fi", "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($interface) If @error Then ExitLoop WEnd ;ConsoleWrite($output & @CRLF) $status = StringRegExp($output, "(?m).+\hTipo:+\h+\h+(.*)\s", 3) ;$status = StringRegExp($output, "(?m).+\hEstado de conexión+\h+\h+(.*)\s", 3) ;$status = StringRegExpReplace($output, "(?s).+Estado de conexión:\h+(\w+).*", "$1") _ArrayDisplay($Status ) If Not @error Then ConsoleWrite("Status: " & $Status[0] & @CRLF) Link to comment Share on other sites More sharing options...
mikell Posted November 25, 2018 Share Posted November 25, 2018 This works for me #include <Array.au3> $output = "Wi-Fi" & @crlf & _ " Tipo: Dedicado" & @crlf & _ " Estado administrativo: Habilitado" & @crlf & _ " Estado de conexión: Conectado" $status = StringRegExp($output, "Estado de conexión:\h+(\w+)", 3) _ArrayDisplay($status) $all = StringRegExp($output, ":\h+(\w+)", 3) _ArrayDisplay($all) jcpetu 1 Link to comment Share on other sites More sharing options...
jcpetu Posted November 25, 2018 Author Share Posted November 25, 2018 mikell, if I copy paste your example it works, but if I just copy the StringRegExp it not even brings an array. Perhaps something on my side I don't get to understand. Thanks a lot for your help. Link to comment Share on other sites More sharing options...
mikell Posted November 25, 2018 Share Posted November 25, 2018 I just tried the code below and it works nice on my PC What exactly doesn't work for you ? #include <Array.au3> #include <constants.au3> Local $interface = Run("netsh interface ip show config", "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($interface) If @error Then ExitLoop WEnd ;Msgbox(0,"", $output) $all = StringRegExp($output, ":\h+(.+)", 3) _ArrayDisplay($all) Link to comment Share on other sites More sharing options...
jcpetu Posted November 26, 2018 Author Share Posted November 26, 2018 mikell, when running netsh interface show interface wi-fi you get: Wi-Fi Tipo: Dedicado Estado administrativo: Habilitado Estado de conexión: Conectado And I'm using StringRegExp to extract only the value of Estado de conexión, in this case the result would be: Conectado Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted November 26, 2018 Share Posted November 26, 2018 @jcpetu Are you sure that you are getting that output? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted November 26, 2018 Share Posted November 26, 2018 Hmm. To be sure please just replace in the pattern the ó by a dot $status = StringRegExp($output, "Estado de conexi.n:\h+(\w+)", 3) Link to comment Share on other sites More sharing options...
jcpetu Posted November 27, 2018 Author Share Posted November 27, 2018 mikel, with the point it works! Thanks a lot. #include <Array.au3> #include <constants.au3> Local $interface = Run("netsh interface show interface wi-fi", "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($interface) If @error Then ExitLoop WEnd ConsoleWrite($output&@CR) $status = StringRegExp($output, "Estado de conexi.n:\h+(\w+)", 3) _ArrayDisplay($status) Link to comment Share on other sites More sharing options...
jchd Posted November 27, 2018 Share Posted November 27, 2018 Switch your source file to Unicode (UTF8) under SciTE and also check wich version of AutoIt you're running. This works for me: Local $s = "Estado de conexión: Conectado " ConsoleWrite(StringRegExp($s, "Estado de conexión:\h+(\w+)", 3)[0] & @LF) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
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