Skip to main content
dublove
Legend
June 21, 2025
Question

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

  • June 21, 2025
  • 1 reply
  • 231 views

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.

1 reply

m1b
Community Expert
Community Expert
June 22, 2025

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.

dublove
dubloveAuthor
Legend
June 22, 2025

You can't get it straight?
Doesn't seem to support that: 

var matcher = /(?<=【)([^】]+)(?=】)/;

 

I used a

if (match[1] === "@")

Hint: Can I really not humanly use a reserved character when it is illegal to use it in the following cases?

m1b
Community Expert
Community Expert
June 22, 2025

Sorry @dublove I'm not sure what you want... I tried to make it as simple as possible. The match gives you the text between the brackets. What did you want?

 

Edit @dublove I've added some more logic to my example above. Hope that helps.