Jump to content
Ketarin forum

A regex question


Rainie
 Share

Recommended Posts

I used the following regex to extract version number of Opera Browser from their FTP (http://ftp.opera.com/pub/opera/desktop/) (I use the RTL mode, but adding .* prefix also works)

<a href="([\d\.]+)/">

But they have an odd sorting algorithm so the build 30.0.1835.125 is located higher on the list than 30.0.1835.88 due to leading "1":

<a href="28.0.1750.40/">28.0.1750.40/</a> 
<a href="28.0.1750.48/">28.0.1750.48/</a> 
<a href="28.0.1750.51/">28.0.1750.51/</a> 
<a href="29.0.1795.47/">29.0.1795.47/</a> 
<a href="29.0.1795.60/">29.0.1795.60/</a> 
<a href="30.0.1835.125/">30.0.1835.125/</a>
<a href="30.0.1835.52/">30.0.1835.52/</a> 
<a href="30.0.1835.59/">30.0.1835.59/</a> 
<a href="30.0.1835.88/">30.0.1835.88/</a>

The goal is to get the bottommost 3-digit-build version number if it exists and starts with .*<a href="([\d\.]{9})\. (== 30.0.1835 in this case), otherwise to get the bottommost 2-digit one.

I've tried regexp methods alongside with Ketarin's functions and variables to no avail.

There are many other sources for the version number, but I'm curious if there is a solution?

I wanted to use a possessive quantifier (something like {ver}\.\d{2,3}+, where {ver}=30.0.1835, but it seems not supported by Ketarin.

 

I will appreciate any suggestions.

Thanks in advance!

Link to comment
Share on other sites

I've already tried the positive lookaheads and conditionals for such purpose.

 

You've done a good job, however, your regex won't work in some rare theoretical cases.

The universal solution seems not achievable without using mathematical comparison.

 

Thanks anyways.

Link to comment
Share on other sites

One option I use on some sites is to add "?C=M" to the URL, which will change the sort order of the resulting files to the date modified. That makes the most recent stuff on the top or bottom. It doesn't work on this site, though, but for future readers -- try that first.

 

In this situation, things are going to be ugly. They're sorting the results alphabetically which makes numbers appear wonky (100 before 20 before 42 before 5 before 8910 before 9). While it might be possible to group and sort them through Ketarin, if you can do it, use another source. It's not worth the effort for a single-use profile.

 

Another option would be to contact Opera and have them fix it on their end. Maybe they have no idea they're making life difficult for their users.

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.