How to match everything except for specified strings?

62 Views Asked by At

Ok so I'm really struggling to figuring this one out. There where other post on here answering this question but non of them worked out for my use case (GREP InDesign).

Input:

meelebox meelebox meeleboxmeeleduelist meeleboxuser meelebox meelebox meelebox

--

Match:

meele meele meelemeeleduelist meeleuser meele meele meele

I got \w+(?=(box))|(?<=box)\w+ to work, but I really want an expression where I only need to write the word once, as it's an expression I use a lot and that might change over time.

I thought I figured it out with this \w+(?=(box))|(?<=\2)\w+ but the \2 doesn't seem to work.

1

There are 1 best solutions below

1
pavi2410 On

The problem you defined doesn't even require RegEx. It can be solved using simple string replace, where you replace occurrences of box with an empty string.

❯ echo "meelebox meelebox meeleboxmeeleduelist meeleboxuser meelebox meelebox meelebox" | sed s/box//g
meele meele meelemeeleduelist meeleuser meele meele meele