Sign in to follow this  
Followers 0
storme

Regex help getting version details

5 posts in this topic

G'day all

I'm extracting version information from a web site. However the field comes out like this

"{Program name containing spaces} {Version number}[ beta {beta number]"

Originaly I was ignoring beta vereions so just ignored it and used this line to get the version number

$sCurrentVersion = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1)

However for something like this "Firefox 12.0 Beta 6" I get a version of 6 when I'd like "12.0 Beta 6"

Now I could write up several lines ofr code to stripe parts from the line till I get what I want.

However, it would get very messy and I'm sure the regex gurus have a simple (complicated looking) single line that does all the work very elegantly. ;)

It has to handle situations like these:

Firefox 12.0 Beta 6

Version = 12.0 Beta 6

Google Chrome 19.0.1084.30 Beta

Version = 19.0.1084.30 Beta

ACDSee 14.2.157

Version = 14.2.157

Flash Player 11.3.300.231 Beta 2 (IE)

Version = 11.3.300.231 Beta 2

Google Chrome 19.0.1084.30 Beta

Version = 19.0.1084.30 Beta

Thanks in advance for any help!

John Morrison

Share this post


Link to post
Share on other sites



$version = StringRegExp($text, "^(?:.+?)(?=d+.)(.*)$", 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)

Share this post


Link to post
Share on other sites

$version = StringRegExp($text, "^(?:.+?)(?=\d+\.)(.*)$", 1)

Thanks Mate!

I did ask for an Expert and I got one. ;)

I did give it a fo myself nad had some of the right elements but couldn't get it to work.

If you don't mind I'm trying to understand the regex and this is what I've got so far.

^ - Start of line

(?:.+?) - NON capture group 1 or more characters

(?= - Can'f find this one in the AutoIT help file?? But I'm guessing it's a look a head

\d+ - One of more digits

\. - Would seem to indicate a full stop (period) ??WHY??

) - end of look ahead

(.*) - Capture ALL

$ - to end of line

OK I get what the period was for now. To look for at least one . in a version number. However there are a few that don't have them so I'll have to remove that to allow for them. Sorry I didn't have one in the examples. :D

So teh new version should look like this.

$version = StringRegExp($text, "^(?:.+?)(?=\d+)(.*)$", 1)

The only thing it didn't do was remove the (ie) from the end of the "Flash Player 11.3.300.231 Beta 2 (IE)" version but that I can live with :) and I think the regex would get complicated to do that one and still pick up everything else. :D

Thanks for the help!

John Morrison

Share this post


Link to post
Share on other sites

this might work a bit better

$version = stringregexp($text, "^(?:.+?)(?=[d.]+)(.*)$", 1)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

this might work a bit better

$version = stringregexp($text, "^(?:.+?)(?=[d.]+)(.*)$", 1)

Unless I made a mistake [d.] means (any digit) or . Period.

But wouldn't that mean that if a program name contains a . then it would mess up?

eg "My great .net updater 4.0" : Version = ".net updater 4.0"

As all versions I have found start with a digit I think I'll leave periods out of it completly.

BUT a big thanks for the suggestion.

Share this post


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
Sign in to follow this  
Followers 0