planetstar Posted April 2, 2014 Posted April 2, 2014 Hello, i have a xml file with the following content: <item Property="Windows 7 Professional" > <item Property="Name" Value="Windows 7Professional x64 Service Pack 1" /> <item Property="Features" Value="Terminal Services in Remote Admin Mode, 64 Bit Edition, Media Center Edition, Multiprocessor Free, OEM-Version" /> <item Property="Edition Type" Value="Professional" /> <item Property="Edition ID" Value="X15-37341" /> From this file i want to extract the following string: Windows 7Professional x64 Service Pack 1 I have tried to extract it with StringRegExpReplace, but it did not work. #Include <File.au3> #Include <Array.au3> $file = "C:tmpos.xml" $xml_file = FileOpen($file, 0) $string = StringRegExpReplace(FileRead($xml_file), '<item Property="Name" Value="([^"]*)" />', "$1") MsgBox(0,"Info", $string) Can somebody help to figure out the right regular expression? Thanks.
sahsanu Posted April 2, 2014 Posted April 2, 2014 Hello, Try this RegExp: $string = StringRegExpReplace(FileRead($xml_file), '(?s).+Name.+?Value=\"(.+?)\".+', "$1") One more thing, remember to use FileClose if you use FileOpen Regards, sahsanu
planetstar Posted April 2, 2014 Author Posted April 2, 2014 It works. Thank you very much sahsanu. Just one question: i'm new to StringRegExpReplace an I was thinking that the variable $1 is a back reference to the result of the first bracket, so why is $1 working and i don't have to use $2. Can you please point this out? Thanks again.
jchd Posted April 2, 2014 Posted April 2, 2014 There is only one capturing group in your pattern. Read help again and realize that (?s) is an option. 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)
planetstar Posted April 2, 2014 Author Posted April 2, 2014 Ok, that makes sense now. I will read the help again. Thanks for helping
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