General idea, is to think of how items can be related to as a group.
One type of group is "everything"; .*
Basically says match everything. And that is fine, but you then want to filter something out.
(.*) match everything
(.*?) match everything, but don't be greedy (the ?)
(.*?)[.*] match everything, but don't be greedy, but only up to a [ followed by anything up to the last ]
(.*?) is referenced in the Replace: as \1
[.*] is not "grouped" (because it was not put in parenthesis), so will not end up in the output name, i.e., that part will be cut from the name
And that may be sufficient for your needs.
RegEx:
- Code: Select all
Match: (.*?)[.*]
Replace: \1
That's the basic premise, but there are always gotchas & nuances.
"file name 1 [gobbly] [gook].txt"
"file name 1 [random.txt"
"file name 1 [random].txt"
What will the above code do with those particular examples? Well...
So depending on what you have, & what you're looking to get, you may need to tweak even more.
RegEx:
- Code: Select all
Match: (.*?)([.*])
Replace: \2 - \1
Now I've placed the [.*] in parens, so I can now reference it in the Replace: (& added a dash).
And in this example, I've switched positions 1->2 to 2->1.
So...
"file name 1 [random].txt"
becomes
"[random] - file name 1.txt"
(I'm not very good at this, but it should give some insight.
And there are varying RegEx versions (& syntax) that may be easier to code, depending...)