Skip to main content
Participating Frequently
February 26, 2026
Open for Voting

expression : word to find

  • February 26, 2026
  • 1 reply
  • 71 views
Hi everyone, I need a new expression to find a specific word in a sentence and apply another style to it.

 

best regard

Fabrice

    1 reply

    Bruno Quintin
    Inspiring
    February 26, 2026

    // Word to be styled
    target = "test";

    // Original text from the layer
    t = text.sourceText;

    // Build a regex to find the target word (case‑insensitive)
    // \b ensures we match whole words only
    regex = new RegExp("\\b" + target + "\\b", "i");

    // Try to find the word in the text
    match = t.match(regex);

    if (!match) {
        // If the word is not found, return the text unchanged
        t;
    } else {
        // Character index where the matched word starts
        start = match.index;

        // Character index where the matched word ends
        end = start + match[0].length;

        // Split the text into three parts:
        // before the word, the word itself, and after the word
        before = t.slice(0, start);
        word = t.slice(start, end);
        after = t.slice(end);

        // Rebuild the full string (not strictly necessary here,
        // but useful if you later modify the structure)
        s = before + word + after;

        // Apply the font only to the character range of the matched word
        t.style.setFont("MyriadPro-Regular", start, end - start);
    }

     

    Participating Frequently
    March 10, 2026

    Merci Quentin, à voir si les développeurs d’Adobe veillent bien remplacer ton script en une simple commande 😊