I have a list of files that all follow the same pattern of either of the following three files, what I need to do is, based on the pattern of each of the three filenames, is set which regex expression pattern to use for the rest of the loop I have.
1234567_-.txt
1234567_-_a_1234567---new000.txt
1234567_-_m_1234567--.txt
I know the following code does not work, but I cannot figure out what I need to with this. If anyone has a better solution or knows how to tweak this, I would greatly appreciate it.
Code: Select all
$matches = regexmatches("$file", "(.*)_([0-9a-zA-Z\-]*)_(s|m|a)_(.*)-([0-9a-zA-Z\-]*)-new([0-9]*)(\.)(txt)$", <crlf>);
$count = gettoken($matches, "count", <crlf>);
if (gettoken($matches, "count", <crlf>) > 5){
$fRegExPat = "(.*)_([0-9a-zA-Z\-]*)_(s|m|a)_(.*)-([0-9a-zA-Z\-]*)-new([0-9]*)(\.)(txt)$";
}
elseif (gettoken($matches, "count", <crlf>) > 3) {
$fRegExPat = "(.*)_([0-9a-zA-Z\-]*)_(s|m|a)_(.*)(\.)(txt)$";
}
else {
$fRegExPat = "(.*)_([0-9a-zA-Z\-]*)(\.)(txt)$";
}
XYplorer Beta Club