Skip to main content
LynxKx
Inspiring
Aug 9, 2024 9:46 PM UTC
Answered

Conditional text in a positive lookbehind grep sequence

I'm trying to create a grep string that will subscript a symbol but only after specific words and not all instances of the symbol. 

In the example below I want the % subscripted when used after Melon and Apple but no other use of % should be subscripted.

I cant figure out what I'm doing wrong?

(?<=[Grape|Orange|Apple|Bananna|Avocado|Melon|Pineapple])%

 

This topic is closed to new replies. Start a new post to keep the conversation going.
FRIdNGE
FRIdNGECorrect answer
Aug 10, 2024 10:13 AM UTC

Robert,

 

Bad answer! …

 

Right Grep syntax:

 

(Grape|Orange|Apple|Bananna|Avocado|Melon|Pineapple)\K%

 

(?<= …) just doesn't work with such a variable list!

 

(^/)  The Jedi

3 replies

Robert at ID-Tasker
Legend
Aug 9, 2024 9:54 PM UTC

[] is for any Character from the list - you should rather use () instead. 

 

Translate
FRIdNGE
FRIdNGECorrect answer
Aug 10, 2024 10:13 AM UTC

Robert,

 

Bad answer! …

 

Right Grep syntax:

 

(Grape|Orange|Apple|Bananna|Avocado|Melon|Pineapple)\K%

 

(?<= …) just doesn't work with such a variable list!

 

(^/)  The Jedi

Translate
LynxKx
LynxKxAuthor
Inspiring
Aug 12, 2024 4:38 AM UTC

Oooh I have not used \K ... thank you!!!

Translate