Skip to main content
LynxKx
Inspiring
August 9, 2024
Answered

Conditional text in a positive lookbehind grep sequence

  • August 9, 2024
  • 1 reply
  • 684 views

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 has been closed for replies.
Correct answer FRIdNGE

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

1 reply

Robert at ID-Tasker
Legend
August 9, 2024

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

 

FRIdNGE
FRIdNGECorrect answer
August 10, 2024

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

LynxKx
LynxKxAuthor
Inspiring
August 12, 2024

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