Target specific words in text

All things .jsx

Moderator: Paul Tuersley

Post Reply
Martylauders
Posts: 1
Joined: February 7th, 2017, 6:11 am

i want to be able to type in text, and have specific words (or words surrounded by specific sumbols, like for example this: [the word]) targetted with a script, so the font automatically gets changed, or he color changes, etc.

Do you guys or girls think this is possible, and if so, how should I handle this?

Thanks!!
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

You can only set one style for a text layer via script, if you need multiple styles you need to create more text layers and find a way to place them.

If you only need to change the color, or other properties that is not the font, you can maybe look into using an expression selector on the text layer.

To find a word you can use

Code: Select all

text.indexOf("word")
to find where the word is.

To find words surrounded by symbols you might have to use a regular expression

Code: Select all

var text = "Lorem [ipsum] dolor [sit] amet"
var match = text.match( /(\[.*?\])/g );
console.log( match ); // Logs ["[ipsum]", "[sit]"]
https://jsbin.com/kesuninehu/edit?js,console

You could then maybe use that with indexOf to find the indexes.

Hopefully that might help you figure something out

Rune
Post Reply