function getHelpOnExpression(hp, expression)
[operators, pieces] = regexp(expression, '\.?[^\w\s."'']+', 'match', 'split');
assignIndex = find(operators=="=");
if isempty(assignIndex)
lhs = '';
else
lhs = strjoin(pieces(1:assignIndex));
expression = strjoin(pieces(assignIndex+1:end));
end

functions = getIdentifiers(expression);
variables = getIdentifiers(lhs);

[variables, ~, i] = intersect([variables, functions], {hp.wsVariables.name});
types = {hp.wsVariables(i).class};
functions = setdiff(functions, {hp.wsVariables.name});

if hp.getHelpForTopics(functions, false, false)
return;
end

operators = unique(operators);
if hp.getHelpForTopics(operators, true, false)
return;
end

if isscalar(variables)
hp.getHelpForTopics(variables, false, false);
elseif ~isempty(variables)
isaText = cellfun(@(x,y)helpUtils.getInstanceIsa(x,y), variables, types, 'UniformOutput', false);
padding = regexp(pad(variables, 'left'), '\s*', 'match', 'once', 'emptymatch');
isaText = [padding; isaText];
hp.helpStr = [isaText{:}];
elseif isempty(functions) && isempty(operators)
hp.getHelpForTopics("ans", false, false);
end
end

function ids = getIdentifiers(expression)
ids = regexpi(expression, '[a-z]\w*(\.[a-z]\w*)*', 'match');
end

% Copyright 2018 The MathWorks, Inc.