Jump to content

StringRegExp trouble


tes5884
 Share

Recommended Posts

Hi Guys,

I'm trying to write a script to check a rss feed if there is an update to Adobe or Firezilla. Trouble is, I cant wrap my brain around StringRegExp, how do I get only the version number so I can compare to my current version and see if it is up to date?

Thanks!

#include <IE.au3>
#include <Array.au3>
#include <CSV.au3>

$lst = "sources.csv"
$csv = _ParseCSV($lst, "", "", 1)



For $i = 0 To UBound($csv, 1) - 1

InetGet($csv[$i][0], "temp.xml")

$1 = FileRead("temp.xml")
$2 = StringRegExp($1, '', 3)


If FileExists($csv[$i][1] & ".txt") Then
If $2[2] > FileReadLine($csv[$i][1] & ".txt", -1) Then
$rslt = MsgBox(4, "", "Updates available! Do you want to be reminded again?")
If $rslt = 7 Then
FileWriteLine($csv[$i][1] & ".txt", $2[2])
EndIf
EndIf
Else
FileWrite($csv[$i][1] & ".txt", $2[2])
EndIf
FileDelete("temp.xml")

Next

Exit
Edited by tes5884
Link to comment
Share on other sites

What exact input syntax do you have and what do you want to extract?

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

try with _StringBetween or

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I'd use:

$sVersion = StringRegExp($sXMLcontent, "(?i)<item>.*?<title>.*?(d+(?:.d+)*).*?</title>), 1)

then use StringSplit then Number to compare each component of both versions. A raw string compare won't work: '10.2.1' < '9.0.1'

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

$sVersion = StringRegExp($sXMLcontent, "(?i)<item>.*?<title>.*?(d+(?:.d+)*).*?</title>", 1)

Sorry for typo. I can't test right now but I hope it's fine.

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

I'm inferring the XPATH...feel free to update it as needed

$oXML=ObjCreate("Microsoft.XMLDOM")

$oXML.loadxml($string) ; load document...the string you read from the file...or use.xml(file)

$oItem = $oXML.selectSingleNode( '//item' )
$oTitle = $oXML.selectSingleNode( '//title' )

ConsoleWrite ($oItem.text & " " & $oTitle.text & @crlf )

update: weakness of regexp...what if there are 2 item's, and only the second includes a title? your regexp would match the first item, but the second title. dom objects are always consistent (when well formatted xpath included)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

That's why I asked for the exact input syntax!

Anyway you're right in that XMLDOM is more reliable in the general case, but the poster insisted on a regexp.

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

I always see similar posts, and always try to open posters to DOM objects. Maybe they are unfamiliar, or don't know about them. It answers the question, just with a better answer (opinion) then actually asked for.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I always see similar posts, and always try to open posters to DOM objects. Maybe they are unfamiliar, or don't know about them. It answers the question, just with a better answer (opinion) then actually asked for.

That's why I asked for the exact input syntax!

Anyway you're right in that XMLDOM is more reliable in the general case, but the poster insisted on a regexp.

I don't know what DOM objects are, hence my confusion.

My apologies..

Edited by tes5884
Link to comment
Share on other sites

Example
#include <Array.au3>
$RSS = InetRead('http://www.filehippo.com/download_adobe_reader/rss')
$RSS = BinaryToString($RSS)

;Get the Text Between the Tag
$sTitle = TagBetween($RSS, 'title')

For $i = 0 To UBound($sTitle) - 1
$sVersion = Version($sTitle[$i])
ConsoleWrite('Index:' & $i & ' Version:' & $sVersion & @CR)
Next

_ArrayDisplay($sTitle)


Func TagBetween($sString, $sTag)
$aRet = StringRegExp($sString, "(?i)(?s)<" & $sTag & ">(.*?)</" & $sTag & ">", 3)
If @error Then Return SetError(@error, @extended, -1)
Return $aRet
EndFunc   ;==>TagBetween

Func Version($sString)
;Remove the Alphabets
$aRet = StringRegExpReplace($sString, "([^0-9.])*", '')
If @error Then Return SetError(@error, @extended, -1)
If $aRet = '' Then Return 0
Return $aRet
EndFunc   ;==>Version

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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

×
×
  • Create New...