Page 1 of 1
Regular Expression Help
Posted: 26 Aug 2019 01:23
by hermhart
Hello, I have the below regular expression and it usually works, but for some reason when using it in a script it does not want to find filenames if they have a '#' in their first group. Would anyone have a suggestion?
([0-9a-z_#\-]*[0-9a-z_#\-]*)([a-z0-9]{3})([0-9]{3})~([0-9a-z\-]*)\.([a-z]*)$
An example of filename would be:
8c-400-r#lt05000~-.txt
Re: Regular Expression Help
Posted: 27 Aug 2019 18:56
by highend
What's the use of doubling [0-9a-z_#\-]*[0-9a-z_#\-]*?
Apart from that, post the script with which the problem occurs...
Re: Regular Expression Help
Posted: 29 Aug 2019 00:15
by hermhart
Please excuse my coding 'skills'. I'm not real good, but I'm trying.
Code: Select all
end get("selecteditemsnames", "<crlf>") == "", "Please make a selection first.";
$source = inputselect(<<<EOD
Choose fields to be wildcard(s):
Example fieds:
1 2 3 4 5
12345678 a05 101 a txt
EOD
, <<<EOD
1 Number
2 Document 1
3 Document 2
4 Revision
5 File Extension
EOD
, <crlf>, 2+8192, , 300, 300, Selection);
//if (strpos($source, "1") != -1) {
if (strpos($source, "1 Number") != -1) {
$result1 = "*";
//$index++;
}
else {
$result1 = "$1";
//$index++;
}
//if (strpos($source, "2") != -1) {
if (strpos($source, "2 Document 1") != -1) {
$result2 = "*";
//$index++;
}
else {
$result2 = "$2";
//$index++;
}
//if (strpos($source, "3") != -1) {
if (strpos($source, "3 Document 2") != -1) {
$result3 = "*";
//$index++;
}
else {
$result3 = "$3";
//$index++;
}
//if (strpos($source, "4") != -1) {
if (strpos($source, "4 Revision") != -1) {
$result4 = "*";
//$index++;
}
else {
$result4 = "$4";
//$index++;
}
//if (strpos($source, "5") != -1) {
if (strpos($source, "5 File Extension") != -1) {
$result5 = "*";
//$index++;
}
else {
$result5 = "$5";
//$index++;
}
$newResult = $result1.$result2.$result3."~".$result4.".".$result5;
$selections = get("SelectedItemsNames", "<crlf>");
Copytext regexreplace($selections, "([0-9a-z_#\-]*[0-9a-z_#\-]*)([a-z0-9]{3})([0-9]{3})~([0-9a-z\-]*)\.([a-z]*)$", $newResult);
foreach($item, "<clipboard>", "<crlf>", "e") {
selfilter "$item", , , 1;
}
Re: Regular Expression Help
Posted: 29 Aug 2019 08:31
by highend
What does this have to do with regular expression(s)?
selfilter isn't working correctly. Why? Look at its
examples in the help file. What does a # stand
for in the pattern? A #? No, it's a metacharacter
for a digit (0-9).
So replace it with [#] (this escapes it!)
before you go into the foreach loop...
Re: Regular Expression Help
Posted: 29 Aug 2019 12:34
by hermhart
highend, thank you so much! I have been completely looking/focusing on the wrong thing in the script.

Re: Regular Expression Help
Posted: 31 Aug 2019 22:35
by hermhart
highend,
I finally got my script to work because of what you pointed out to me. But I'm curious, I understand that # can mean to match a number, but I thought the way to escape it would be to do it like this: \#
I'm just curious if you can tell me where in the help that it mentions to use [#] instead of \#.
Just trying to learn for myself.
Thank you.