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?
Hints, tips and tricks for newbies
2 posts • Page 1 of 1
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 */