I need to extract a sub-string after a specific delimiter, but if the specified delimiter is between two other tags it should be ignored.

For example, take this test string:

> 
> The quick <"@brown fox"> jumps over the lazy dog. The quick @*brown fox
>  jumps over the lazy dog*
> 
> 
> 

The desired output would be:

> 
> *brown fox jumps over the lazy dog*
> 
> 
> 

This is because the first found @ delimiter is between two " " and so should be ignored, the second @ delimiter is not inside " " and so the text afterwards should be extracted.

I am able to find the starting position of the @ delimiter by using `Pos` and extracting the text to the right of it as shown below:

```
procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
  I: Integer;
begin
  S := 'The quick <"@brown fox"> jumps over the lazy dog. The quick @brown fox jumps over the lazy dog';
  I := Pos('@', S);
  if I > 0 then
  begin
    ShowMessage(Copy(S, I, Length(S)));
  end;
end;

```

However this will always find the first @ delimiter regardless if it is surrounded by two " " or not. The result from the above is:

> 
> @brown fox"> jumps over the lazy dog. The quick @*brown fox jumps over
>  the lazy dog*
> 
> 
> 

where the desired result should be:

> 
> *brown fox jumps over the lazy dog*
> 
> 
> 

How can I change the code to ignore @ delimiters when using `Pos` if the delimiter is between two " " tags? I only want to find the first @ delimiter and copy the text afterwards.

It also does not matter if there are any other @ delimiters after the first valid one is found, for example this should also be valid:

> 
> The quick <"@brown fox"> jumps over the lazy dog. The quick @*brown fox
>  jumps@ ov@er the lazy@ dog*
> 
> 
> 

Should still return:

> 
> *brown fox jumps over the lazy dog*
> 
> 
> 

Because we are only interested in the first valid @ delimiter, ignoring anything else afterwards and ignoring anything between two " " tags.

Please note although I have tagged Delphi I do primarily use Lazarus so ideally I would need help coming up with a solution that does not use magic help with string helpers etc.

Thanks.