New York University-IELTS Prize-James Bond–Invoice.pdf
What I tried to achieve is to add a tag with any text between the last and second to last “–”, in this case, the name “James Bond”.
I think it is possible to achieve this through regular expression, but I ask Copilot and it gives me an expression that selects any text between the first and second “–” in the name.
Could anyone give some suggestions on the correct expression?
Do you have - and –, ie dashes and endashes in the name? Because that’s what your example looks like here.
If it’s only one kind of dashes .*-(.*?)-[^-]*$
Might do the trick. \1 then contains the string
Regular Expressions, frankly, hurt my brain. But there are a lot of resources available on the internet, including “cheat sheets” which might be useful. Also some books. Just do a search for “regular expressions”.
May I ask why?
A filename isn’t intended to be a full description of a document, any more than you’d include your height and weight in your name. Shorter filenames are sufficient more often than not. In fact, looking at your example filename, why not use NYU instead of New York University ?
If, for some reason, you must specify the weight, dimensions, and content of a package within a single blank space, then it makes sense to write 100g-30cm-20cm-20cm-plastic toy. Such scenarios are common on download sites, where preservation of file metadata is less than consistent.
And though my original question still stands, here is a simple example from this contrived filename…
set od to AppleScript's text item delimiters
set r to "New York University-IELTS Prize-Bob-Invoice.pdf"
set AppleScript's text item delimiters to {"-", "–"}
set {pre, suf} to {text items 1 thru -3, text item -1} of r
set n to {pre, “BLUEFROG", suf}
set AppleScript's text item delimiters to "–"
set n to n as string
set AppleScript's text item delimiters to od
return n
And obviously, instead of hard-coding the value, BLUEFROG in n can be derived from a variety of sources, e.g, display dialog, pulled from custom metadata, parsed from some other document, etc.
IMHO I’d say that’s a very specific niche example, not prescriptive for general document management, at least not in the context of much of how DEVONthink is used. Also, long filenames sometimes can be problematic, so it’s not just a matter of aesthetics or whim I’m basing my question on. The same can be said of punctuation (or emoji) in filenames.
I agree that it’s not excellent document management to stuff everything into the file name. Nevertheless, that’s still better than no management at all. Not every organization invests time and effort in setting up and running a proper system, even when the benefits of such a system have been well-known.
I’ve personally dealt with large (100+ people), respected organizations which use the equivalent of Facebook for work communications. In that case, long, informative file names are what makes retrieval possible. IMHO this is definitely not a niche case in an ad-hoc, informal business culture. You’re perhaps right, though, that most DT users fortunately don’t have to endure such a culture.