Jump to content
Ketarin forum

how to use regex in a function


dutchclimber
 Share

Recommended Posts

Hi all,

 

I am a frequent user of Personal Backup. http://personal-backup.rathlev-home.de/index-e.html One of these home grown hidden gems (backup)...

 

Obviously I want to integrate this in Ketarin.

 

Grabbed the version of the homepage (actually a framepage)

(http)://personal-backup.rathlev-home.de/persback-e.html

and currently the version comes out like this:

4.3.4.8

 

The file location is on

(http)://personal-backup.rathlev-home.de/download/pb-setup-4.3.0408.exe

 

So thanks to MadDog's post about functions I have come up with this:

(http)://personal-backup.rathlev-home.de/download/pb-setup-{version:split:.:0}.{version:split:.:1}.{version:split:.:2}{version:split:.:3}.exe

 

That however doesn't work because the version number 4.3.4.8 is represented as 4.3.0408 in the file's direct link. Now I could hardcode those 0-s in but I know this developer. He WILL go into double digits at some point.

 

My first idea was to use regex-replace (because being new to and amazed by regex I think we might even solve worldpeace with it but I have no clue how.

 

Question 1) can I integrate regex into functions? (documentation seems to suggest it)

Question 2) can somebody help me solve this puzzle...?

 

Cheers!

R

Edited by dutchclimber
Link to comment
Share on other sites

Question 1) can I integrate regex into functions? (documentation seems to suggest it)

I'll leave this one to Flo. ;)

Question 2) can somebody help me solve this puzzle...?

This is a much easier solution... 'scrape' the version from the download URL and 'scrape' the entire download URL dynamically... in case it changes...

<?xml version="1.0" encoding="utf-16"?>
<Jobs>
 <ApplicationJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <DownloadBeta>Avoid</DownloadBeta>
   <DownloadDate xsi:nil="true" />
   <CheckForUpdatesOnly>false</CheckForUpdatesOnly>
   <VariableChangeIndicator>{version}</VariableChangeIndicator>
   <CanBeShared>true</CanBeShared>
   <ShareApplication>false</ShareApplication>
   <ExclusiveDownload>false</ExclusiveDownload>
   <HttpReferer />
   <Variables>
     <item>
       <key>
         <string>version</string>
       </key>
       <value>
         <UrlVariable>
           <RegexRightToLeft>false</RegexRightToLeft>
           <VariableType>RegularExpression</VariableType>
           <Regex>(?:"|')\w+:\/\/[\w@][\w.:@]+\/?[\w\.?=%&=\-@/$,]*[\w\.?=%&=\-@/$.]*-([\d.]+)\.(?:exe|7z|zip|zip2|bz|bz2|bzip|gz|gzip|jar|lha|lzh|lzw|pak|rar|sit|sit!|sit5|sitd|sithqx|sitx|tz|wsz|cab|msi|bin|img|iso|xpi|pbp)(?:"|')</Regex>
           <Url>http://personal-backup.rathlev-home.de/persback-e.html#download</Url>
           <Name>version</Name>
         </UrlVariable>
       </value>
     </item>
     <item>
       <key>
         <string>download_url</string>
       </key>
       <value>
         <UrlVariable>
           <RegexRightToLeft>false</RegexRightToLeft>
           <VariableType>RegularExpression</VariableType>
           <Regex>(?:"|')(\w+:\/\/([\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*[\w\.?=%&=\-@/$.]*\.(?:exe|7z|zip|zip2|bz|bz2|bzip|gz|gzip|jar|lha|lzh|lzw|pak|rar|sit|sit!|sit5|sitd|sithqx|sitx|tz|wsz|cab|msi|bin|img|iso|xpi|pbp))(?:"|')</Regex>
           <Url>http://personal-backup.rathlev-home.de/persback-e.html#download</Url>
           <Name>download_url</Name>
         </UrlVariable>
       </value>
     </item>
   </Variables>
   <ExecuteCommand />
   <ExecutePreCommand />
   <Category>Utilities</Category>
   <SourceType>FixedUrl</SourceType>
   <DeletePreviousFile>false</DeletePreviousFile>
   <Enabled>true</Enabled>
   <FileHippoId />
   <LastUpdated xsi:nil="true" />
   <TargetPath>{target}\{category}\{appname:replace: :_}_v{version:replace: :_}.{url:ext}</TargetPath>
   <FixedDownloadUrl>{download_url}</FixedDownloadUrl>
   <Name>Personal Backup</Name>
 </ApplicationJob>
</Jobs>

Import the XML and tweak to your needs... hope this helps. If you want the truncated version instead, just tweak the {version} regex and URL for that.

Link to comment
Share on other sites

 

 

Question 1) can I integrate regex into functions? (documentation seems to suggest it)

I think he means regex and regexreplace functions, they are both post-MadDog examples.

Example #1
date:26.02.2009
{variable:regexreplace:([0-9]{1,2\}).([0-9]{1,2\}).([0-9]{4\}):$3-$2-$1}
results in
2009-02-26

Example #2
version:5.1.2
{version:regexreplace:(\d\.\d\.\d):ABC_$1}
results in
ABC_5.1.2

Example #3
version:5.1.2
{version:regex:(\d\.\d)\.\d:1}
results in
5.1

-----------------------

As for worldpeace I don't think M$ thought about that... or they will charge you. ;) Edited by necrox
Link to comment
Share on other sites

@ CybTekSol

Errrrr. As a novice regex-er I would not call that easier! But it's good study material. Maybe the word 'elegant' is more appropriate.

Don't let the regex I used intimidate you dutchclimber, it is not that difficult if you break it down and study it with Expresso which I highly recommend for regex development. Expresso is freeware and it is what I used to develop the {download_url} regex above that is part of my improved 'generic template'. This regex will capture the first URL for an app on a page and can be quickly modified with 'anchors' if you need to capture a different app URL from a given page. This is the first time I have posted this regex here to my knowledge. I was hoping FranciscoR would be impressed! Keep it handy as you will probably embrace it as I have if you use Ketarin long enough. ;) It was meant to invoke curiosity and remember, regex is your best friend with Ketarin IMHO! BTW, Expresso is available HERE.

Link to comment
Share on other sites

well thanks! Can't speak for FransiscoR, but I am impressed!

 

The wife asked what the cursing was good for yesterday evening ....

 

Reason is I have been studying your regeex thoroughly. Don't understand everything (yet) but the generic structure I've got in my fingers now (dutch expression) (more or less). Even figured out the anchor thing you mentioned.

 

... and meanwhile have adapted it for most of my downloads :-D.

 

Thanks for pointing out Expresso... (anotherone to add to Ketarin!)

 

R

Link to comment
Share on other sites

@ CybTekSol

Errrrr. As a novice regex-er I would not call that easier! But it's good study material. Maybe the word 'elegant' is more appropriate.

Don't let the regex I used intimidate you dutchclimber' date=' it is not that difficult if you break it down and study it with Expresso which I highly recommend for regex development. Expresso is freeware and it is what I used to develop the {download_url} regex above that is part of my improved 'generic template'. This regex will capture the first URL for an app on a page and can be quickly modified with 'anchors' if you need to capture a different app URL from a given page. This is the first time I have posted this regex here to my knowledge. I was hoping FranciscoR would be impressed! Keep it handy as you will probably embrace it as I have if you use Ketarin long enough. ;) It was meant to invoke curiosity and remember, regex is your best friend with Ketarin IMHO! BTW, Expresso is available HERE.

I was surprised yeah, I will test it. It's so abstract you can create several global variables with it. ;)

Link to comment
Share on other sites

This could be easily adapted to my SF template, but on a multi-DL page I still need the same before/after anchors I'm using right now. If HTML changes a lot, DL breaks, as always. But very interesting - and innovative - solution for single-DL page (smell of vacations =)). Do like it.

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.