Skip to main content
dublove
Legend
Jun 21, 2025 3:43 PM UTC
Question

How to get the characters in 【】, in the script file name?

For example, my script name has two cases:
Rename Links with Caption behind 【@】 characters.jsx
Rename Links with Caption behind 【】characters.jsx

 

The key character of the first one is @, the second one is empty

Now I want to get the characters between【】.

If there is content in 【】, get it, if  it is empty, get empty("").

 

Thank you very much.

5 replies

m1b
Community Expert
Community Expert
Jun 22, 2025 1:07 AM UTC

Hi @dublove how about this...

 

var scriptName = decodeURI(File($.fileName).name);
var matcher = /【([^】]+)】/;
var match = scriptName.match(matcher);

if (!match)
    alert('There was no brackets in script name.');
else if (0 === match[1].length)
    alert('There was no text inside the brackets.');
else if (match[1] === '@')
    alert('There was "@" inside the brackets.')
else if (match[1][0] === '@')
    alert('There was "@" and "' + match[1].slice(1) + '" inside the brackets.')
else
    alert('Text inside brackets = "' + match[1] + '"');

 

(For anyone else reading this note that the OP's filename includes lenticular brackets.)

- Mark

 

P.S. please just use the one tag "Scripting" to your posts like this. Do not add other tags "Bug", "Feature Request" etc. unless it is actually about those things.

 

Edit 2025-06-22: added a couple more options to the checking of match.

Translate
dublove
dubloveAuthor
Legend
Jun 22, 2025 6:28 AM UTC
if (match[1] === '@')

@ Reserved characters, Tip: Prohibition of use

Translate