Find & Replace: Regex - "replace only first match and ignore others"

Hi SDL community,

I'd like to find and capture only the first "text" in each segment and replace it with e.g. "paraghraph

Segment 1: In years of attending school, most of us have dealt with a number of different technical texts, or texts intended to educate the reader in a particular subject or skill through in-depth study and practice texts.(do not capture or even when matched, do no replace this one)

Segment 2: Technical texts, such as a chemistry textbook or car repair manual texts, which represents any verse or prose work meant to be instructional text.

What would be the regex for:

Find: ......

Replace: .....

Parents
  • You could search for this:

    (?<!\btexts?\b.+)texts?

    Then replace with this:

    paragraph

    Basically a negative lookbehind so you only find the first "text" or "texts" and then "text" or "texts".  Replace is simple as you are finding the first occurrence so you just replace it with whatever text you like.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

Reply
  • You could search for this:

    (?<!\btexts?\b.+)texts?

    Then replace with this:

    paragraph

    Basically a negative lookbehind so you only find the first "text" or "texts" and then "text" or "texts".  Replace is simple as you are finding the first occurrence so you just replace it with whatever text you like.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

Children