Extracting links with numeric value in file name

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
rlchase2006
Newbie
Posts: 7
Joined: Thu Oct 12, 2006 1:04 pm
Location: Hampton, VA
Contact:

Extracting links with numeric value in file name

Post by rlchase2006 » Sat Jun 06, 2020 12:38 pm

I have a file that contains links. I want to extract only links that have a numeric value in them like a 9, or a 5, or both. But the number can be in any location in the file name. I want to exclude all other file names of various lengths.
Is there a simple way of doing this?

ex: https://something.com/absd9gh.txt
https://something.com/a9bschy.txt
https://something.com/something/aa9bs59.txt
Chase

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Extracting links with numeric value in file name

Post by hagchr » Sat Jun 06, 2020 8:31 pm

Hi, There are different ways to solve it. If there is one link per row then one way could be (required code very short, but added explanation in case you have not worked with RegEx> before):

Code: Select all

LabelToVar>strInfo,strLinks

// Use RegEx> to match strings:

// https:// 
// followed by zero or more characters (.*)
// followed by a digit (\d)
// followed by zero or more characters (.*)
// followed by .txt (/.txt where / is escape to just look for literal . not wild card .) 
// initial (?-s) directs RegEx> that . should not match any eol character

Let>tmp0=(?-s)https://.*\d.*\.txt
RegEx>tmp0,strLinks,0,link,nlink,0

// List the result
Let>Res=
Let>ctr=0
While>ctr<nlink
  Add>ctr,1
  Let>tmp=link_%ctr%
  Let>Res=%Res%%tmp%%CRLF%
EndWhile
MDL>Res

/*
strInfo:
https://something.com/absd9gh.txt
https://something.com/a9bschy.txt
kl;k;
k;lk

https://something.com/something/aabs.txt 
https://something.com/a9bschy.txt
*/

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts