Jump to content
Ketarin forum

Regex not working properly


Guest Profpatsch
 Share

Recommended Posts

Guest Profpatsch

I want to get a version name from a sourceforge-folder:

 

URL:

http://freefr.dl.sourceforge.net/project/dev-cpp/Binaries/Dev-C%2B%2B%20{ver}/devcpp-{ver}_setup.exe

 

{ver}-URL:

http://freefr.dl.sourceforge.net/project/dev-cpp/Binaries/?C=N;O=D

 

URL-Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
 <title>Index of /project/dev-cpp/Binaries</title>
</head>
<body>
<h1>Index of /project/dev-cpp/Binaries</h1>
<ul><li><a href="/project/dev-cpp/"> Parent Directory</a></li>
<li><a href="Dev-C++%20version%204.9.9.1/"> Dev-C++ version 4.9.9.1/</a></li>
<li><a href="Dev-C++%20version%204.9.9.0/"> Dev-C++ version 4.9.9.0/</a></li>
<li><a href="Dev-C++%20for%20Linux%200.7.0/"> Dev-C++ for Linux 0.7.0/</a></li>
<li><a href="Dev-C++%204.9.9.2/"> Dev-C++ 4.9.9.2/</a></li>
<li><a href="Dev-C++%204.9.8.0/"> Dev-C++ 4.9.8.0/</a></li>
<li><a href="Dev-C++%204.9.7.0/"> Dev-C++ 4.9.7.0/</a></li>
<li><a href="Dev-C++%204.9.6.0/"> Dev-C++ 4.9.6.0/</a></li>
<li><a href="Dev-C++%204.9.5.0/"> Dev-C++ 4.9.5.0/</a></li>
<li><a href="Dev-C++%204.9.4.1/"> Dev-C++ 4.9.4.1/</a></li>
<li><a href="Dev-C++%204.9.4.0/"> Dev-C++ 4.9.4.0/</a></li>
<li><a href="Dev-C++%204.9.3.0/"> Dev-C++ 4.9.3.0/</a></li>
<li><a href="Dev-C++%204.9.2.0/"> Dev-C++ 4.9.2.0/</a></li>
<li><a href="Dev-C++%204.9.1.0/"> Dev-C++ 4.9.1.0/</a></li>
<li><a href="Dev-C++%204.0%20full%20package%20includes%20Mingw%20compiler/"> Dev-C++ 4.0 full package includes Mingw compiler/</a></li>
<li><a href="4.01%20update/"> 4.01 update/</a></li>
</ul>
</body></html>

 

Problem: There are the "version"-files and the "Linux"-file before the real version I want to get (4.9.9.2).

 

My solution: Regex:

(?<!(version%20))(?<! )\d\.\d\.\d\.\d

The editor says it works (the version number is blue).

But when I want to update it, it says:

Dev-C++ with MinGW/GCC The downloaded file is not a binary file type (text/html; charset=utf-8). Possibly there is an error page. Status code: 200 (OK) (http://freefr.dl.sourceforge.net/project/dev-cpp/Binaries/Dev-C%2B%2B%20/devcpp-_setup.exe)

Clearly, it hasn't included the version number.

 

Did I do sth. wrong or is it a bug?

Link to comment
Share on other sites

Hm, hard to say. The issue occurs because in the editor it highlights the full regex match, while during download, it uses the value of the first group if multiple groups are used in the regular expression.

 

I think it makes sense to adjust Ketarin to not use the first group, but the first group that contains a match. Any objections?

Link to comment
Share on other sites

  • 2 weeks later...

This isn't a capturing regex:

(?<!(version%20))(?<! )\d\.\d\.\d\.\d

It's "matching" the text (blue) but it isn't CAPTURING the match that's desired (red). That requires a couple more para's, as so:

(?<!(version%20))(?<! )(\d\.\d\.\d\.\d)

 

Flo, I anticipate that change would likely cause problems, as it's not really how regex is intended. A "capture" isn't the same as a "match" and I don't think the difference should be muddled. If people are capable enough to use the system with regex, they should be encouraged to use a capture, not provide a lazy out for them - as that will almost assuredly result in more support requests trying to see why something that shouldnt match, is.

Link to comment
Share on other sites

  • 4 months later...

I think using the first group or the first group with a match is not the best way to do this at all. Sometimes, groups have to be used in regexes to find a match at all. It should in my opion possible to (might be optionally) manually select which group to be used.

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.