Skip to main content
Shulipa Bernad
Inspiring
January 14, 2021
Answered

Check the specific name of the prefix in the name of the active document.

  • January 14, 2021
  • 3 replies
  • 359 views

Hello everyone! How to check if the name of the active document is prefixed with "[OK!]"?

Example: [OK!] MyDocument_01.

Grateful for the help!

This topic has been closed for replies.
Correct answer Manan Joshi

You need to escape [] and also remove the unwanted spaces in the regex. Try the following

if (activeDocument.name.match (/^\[OK!\]/)){alert ("true")}

-Manan

3 replies

Kukurykus
Legend
January 14, 2021

 

!activeDocument.name.indexOf('[OK!]')

 

Shulipa Bernad
Inspiring
January 14, 2021

Great! Kukurykus  your script also works well. Thanks

Shulipa Bernad
Inspiring
January 14, 2021

 Manan Joshi , thanks for the excellent tip. It worked really well.

 
Mylenium
Legend
January 14, 2021

Could be as simple as a strict regex match. You might want to read up on that stuff and possibly additional string processing.

 

Mylenium

Shulipa Bernad
Inspiring
January 14, 2021

I tried something like this, but to no avail.

if (activeDocument.name.match (/ ^ [OK!] /)) {alert ("true")}

Manan JoshiCommunity ExpertCorrect answer
Community Expert
January 14, 2021

You need to escape [] and also remove the unwanted spaces in the regex. Try the following

if (activeDocument.name.match (/^\[OK!\]/)){alert ("true")}

-Manan

-Manan