Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
Martylauders
Topic Author
Posts: 1
Joined: Tue Feb 07, 2017 6:11 am

Target specific words in text

Tue Feb 07, 2017 6:16 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: 20
Joined: Fri Nov 04, 2016 3:18 pm
Contact:

Re: Target specific words in text

Tue Feb 07, 2017 7:00 am

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
text.indexOf("word")

to find where the word is.

To find words surrounded by symbols you might have to use a regular expression
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

Who is online

Users browsing this forum: No registered users and 3 guests