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
Regular Expression Help
Re: Regular Expression Help
What's the use of doubling
Apart from that, post the script with which the problem occurs...
[0-9a-z_#\-]*[0-9a-z_#\-]*
?Apart from that, post the script with which the problem occurs...
One of my scripts helped you out? Please donate via Paypal
Re: Regular Expression Help
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
What does this have to do with regular expression(s)?
examples in the help file. What does a
for in the pattern? A
for a digit (0-9).
So replace it with
before you go into the foreach loop...
selfilter
isn't working correctly. Why? Look at itsexamples in the help file. What does a
#
standfor in the pattern? A
#
? No, it's a metacharacterfor a digit (0-9).
So replace it with
[#]
(this escapes it!)before you go into the foreach loop...
One of my scripts helped you out? Please donate via Paypal
Re: Regular Expression Help
highend, thank you so much! I have been completely looking/focusing on the wrong thing in the script.
Re: Regular Expression Help
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.
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.