Jump to content

Lost with extracting a String into a variable with StringRegExpReplace


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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