Jump to content

How can I create compatible regex patterns for each language?

Recommended Posts

cmd systeminfo output separately for each language so I want to make my mold compatible for all
cmd systeminfo output

in English

Original Install Date:     5/26/2020, 12:02:21 AM

in Spanish

Fecha de instalación original :     5/26/2020, 12:02:21 AM

in Russian

Дата установки : 5.26.2020, 12:02:21


Local $iPID = Run('systeminfo', '', @SW_HIDE, 2)
If @error Or Not $iPID Then Exit
Local $sStdOut = ""

    $sStdOut &= StdoutRead($iPID)
Until @error

$regex = StringRegExp($sStdOut, "Date:|original:|установки:\h(\d{2}.\d{2}.\d{4})\W(?=[^,])\s\d{2}|(\d{2}\\d{2}\\d{4})\W(?=[^,])\s\d{2}", 3)

If IsArray($regex) Then
    For $Y = 0 To UBound($regex) - 1
    ConsoleWrite($regex[$Y] & @CRLF)



Link to post
Share on other sites


Maybe, an easier solution would be to split the systeminfo output with @CRLF and grab the line where the information you are looking for appears, since it should always return the same number of lines in the same order :)


Or you can use these tricks to get a list of Properties with standard names:



Edited by FrancescoDiMuro

Click here to see my signature:




Link to post
Share on other sites

I sincerely doubt that spanish and russian systems show 12-hour times since their locale use a 24-hour clock. Also their date locale is dd/mm/yyyy, just like yours and mine (you're both French IIRC).

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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites

I'm italian :D
By the way, using something like this should work as long as the number of information obtained by systeminfo are the same and in the same order:

#include <String.au3>


Func Test()

    Local $intPID, _
          $strSTDOutRead, _
          $arrSTDOutRead, _

    $intPID = Run('systeminfo', '', @SW_HIDE, 2)
    If @error Then Return ConsoleWrite("Run ERR: " & @error & @CRLF)

    While 1
        $strSTDOutRead &= StdoutRead($intPID)
        If @error Then ExitLoop

    ; ConsoleWrite($strSTDOutRead & @CRLF)

    $arrSTDOutRead = StringSplit($strSTDOutRead, @CRLF, $STR_ENTIRESPLIT)

    ; _ArrayDisplay($arrSTDOutRead)

    $strOriginalInstallationDate = StringRegExp($arrSTDOutRead[11], "[^:]+:\h*(.+)", $STR_REGEXPARRAYMATCH)[0]

    ConsoleWrite("$strOriginalInstallationDate = " & $strOriginalInstallationDate & @CRLF)



$strOriginalInstallationDate = 10/12/2019, 11:06:12

Then, the Powershell solution would be nice to use as well, isn't it? :)

Edited by FrancescoDiMuro

Click here to see my signature:




Link to post
Share on other sites

Seems to work better 


I fixed it like this works fine for me

ConsoleWrite(_InstallDate() & @CRLF)

Func _InstallDate()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From Win32_OperatingSystem")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringRegExpReplace($oObjectFile.InstallDate, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)", "$1")
    Return SetError(1, 0, 0)
EndFunc   ;==>_InstallDate


Edited by youtuber
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...