Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guide ,
Jun 21, 2025 Jun 21, 2025

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.

TOPICS
Bug , Feature request , How to , Scripting
159
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2025 Jun 21, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 21, 2025 Jun 21, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2025 Jun 21, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 21, 2025 Jun 21, 2025

wait for...me

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 21, 2025 Jun 21, 2025
LATEST
if (match[1] === '@')

@ Reserved characters, Tip: Prohibition of use

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines