This feels a bit jenky, but maybe it'll work. I'm making a couple of assumptions, so you'll probably need to refine. Here is a list of cases that attempt to match individual terms:
{HoldPattern[Times[_, Power[E, Times[___, z, ___]]]],
HoldPattern[Power[E, Times[___, z, ___]]],
Power[E, z],
HoldPattern[Times[___, Power[y, _], ___]],
HoldPattern[Times[___, y, ___]],
HoldPattern[Times[___, x, ___]],
y,
x}
You can turn this into a single pattern with Alternatives.
Your test didn't make much sense to me, since you seem to want to match the whole expression at once, so instead I defined a helper predicate:
IsMatch[expr_Plus] :=
AllTrue[List @@ expr, IsMatch];
IsMatch[expr_] := With[
{cases =
{HoldPattern[Times[_, Power[E, Times[___, z, ___]]]],
HoldPattern[Power[E, Times[___, z, ___]]],
Power[E, z],
HoldPattern[Times[___, Power[y, _], ___]],
HoldPattern[Times[___, y, ___]],
HoldPattern[Times[___, x, ___]],
y,
x}},
MatchQ[expr, Alternatives @@ cases]]
Some tests:
testCases =
{b y^-3 + c E^(k z),
a*x + b*y^n + c*Exp[k*z],
a*x + b*y^n,
a*x + b*y^n + c*Exp[k*z],
a*x + b*y^1 + c*Exp[k*z],
x + b*y + Exp[k*z],
a x,
b y,
Exp[z]};
IsMatch /@ testCases
(* {True, True, True, True, True, True, True, True, True} *)
a,bcannot both be zero andccan never be zero? It is also a good idea to include some test patterns. And what isf[q]? Thanks. – Syed Oct 22 '22 at 16:25f[q]is just used for test. It could be anything. I am looking for a pattern that is the sum of these terms except for 0 which is0*x+0*y^n+0*Exp[k*z]. – Curious Cat Oct 22 '22 at 16:31" And Exp[k*z] should include the case Power[e,k*z]"which meansccannot be zero? – Syed Oct 22 '22 at 16:33ccan be 0.a*x+b*y^nis also the matched expression.Exp[k*z]is mathematically identical toPower[e,k*z]. However, they have different Heads so the Mathematica cannot identify both at the same time using one pattern. – Curious Cat Oct 22 '22 at 16:37