(EDIT: The subject has been adapted to better reflect the problem & solution)
I have some trouble with the following situation:
tested filename: “Some filename [5309272820375] [µA].mp4”
In this filename I want to capture the media identifier between the first set of brackets, and show this in a column. There’s a second set of brackets that has the symbol “µ” right after the opening bracket), and this is not a media identifier, it indicates a series of ‘labels’ - in this case just label “A” (for Audio-only). I use this instead of the icon labels in Opus because it shows up much faster in my “labels” column. Displaying media identifiers and labels in two separate columns is, of course, not a problem, using evaluator columns.
The problem occurs when both types of brackets appear in the same filename, as in the example above. I can’t seem to get the first one - the media identifier - with a single RegEx call, like this:
if (IsDir(path+"\\"+name)) return "";
c = Count(name, "["); if (c==0) return "-"; //name is the selected file above
if (RegEx(name, ".*\[[^@µ]+")) Output("Ok, the evaluator works.");
//The line below doesn't work as expected because it doesn't do non-greedy!
if (RegEx(name, ".*\[[^@µ]+")) return RegEx(name, ".*\[([^@µ\]]+).*", "\1");
return "?";
What I’m trying to do here is picking up all characters within the particular set of brackets which does NOT have “@” or “µ” immediately after the opening bracket. (If no such thing is found, it returns an empty string). Line 3 just gives some output, confirming that the “if” test works. So the same “if” on line 5 does of course also work. However, the RegEx doesn’t work as expected. In fact, it seems to fail without error, going on with line 6, because the the column shows the question mark. Wtf?
So my question would normally be, how and where exactly to add the non-greedy indicator? Normally, “In ECMAScript, all the forms of repetition count can be followed by the character ? which designates a non-greedy repetition” (quoting the Microsoft page referred to in the Regular Expressions page of the Opus manual). I tries several things, but none was working.
But another, prior question would be: why is the Regex on line 5 being skipped altogether, going on with line 6?
I’m fairly familiar with RegEx but not exactly an in-dept expert.
PS. I can solve the problem of course: I can put the filename in a variable, remove the first bracket if followed by an unwanted character, and then do the exact same regular expression: this works perfectly:
if (c==1 && RegEx(name, ".*\[[^@µ]+")) return RegEx(name, ".*\[([^@µ\]]+).*", "\1");
//If multiple bracketed values, some of which of the types "[@" or "[µ" ...
nn = Replace(name, "[@", ""); nn = Replace(nn, "[µ", "");
if (RegEx(nn, ".*\[[^@µ]+")) return RegEx(nn, ".*\[([^@µ\]]+).*", "\1");
return "";
But this is not how we’re supposed to roll with RegEx. (I feel Rick-Rolled like in the good old days).