Skip to main content
Inspiring
May 21, 2025 4:17 PM UTC
Answered

Nonbreaking space and GREP in UXP

How to check if a character is a nonbreaking space in UXP?

if (chars[chars.indexOf(char) - 1].contents === " ") {
            console.log("yes");
          }

I can't use \u00A0 or /~S/. The first one doesn't work, the second can't be used in .jsx UXP.

Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Legend
May 22, 2025 5:41 PM UTC
quote

Thank You for help.
Correct answer is

if (myCharacter.contents.toString() === "NONBREAKING_SPACE")

By @mateuszp13156491

 

You can save time on converting to string and just compare numeric value:

 

if (myCharacter.contents === 1397645907)
{
    alert("Non Breaking Space")
};

 

3 replies

Community Expert
May 22, 2025 5:41 AM UTC

What about using 160 but the hex is \x{00A0} 

Also found this https://developer.adobe.com/indesign/dom/api/s/SpecialCharacters/#:~:text=NONBREAKING_SPACE%20%3D%201397645907

 

 

Translate
Inspiring
May 22, 2025 8:15 AM UTC

Thank You for help.
Correct answer is

if (myCharacter.contents.toString() === "NONBREAKING_SPACE")
Translate
Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Legend
May 22, 2025 5:41 PM UTC
quote

Thank You for help.
Correct answer is

if (myCharacter.contents.toString() === "NONBREAKING_SPACE")

By @mateuszp13156491

 

You can save time on converting to string and just compare numeric value:

 

if (myCharacter.contents === 1397645907)
{
    alert("Non Breaking Space")
};

 

Translate