Skip to main content
expr = 2 x + x^2 MyFun1[1, x] + x^3 MyFunction[2MyFun2[2, x];

p = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {}, Heads -> False]

{{2, 2}, {3, 2}}

Extract[expr, p]

{MyFun1[1, x], MyFun2[2, x]}

q = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {-1}]

{{2, 2, 0}, {3, 2, 0}}

Extract[expr, q]

{MyFun1, MyFun2}

expr = 2 x + x^2 MyFun1[1, x] + x^3 MyFunction[2, x];

p = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {}, Heads -> False]

{{2, 2}, {3, 2}}

Extract[expr, p]

{MyFun1[1, x], MyFun2[2, x]}

q = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {-1}]

{{2, 2, 0}, {3, 2, 0}}

Extract[expr, q]

{MyFun1, MyFun2}

expr = 2 x + x^2 MyFun1[1, x] + x^3 MyFun2[2, x];

p = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {}, Heads -> False]

{{2, 2}, {3, 2}}

Extract[expr, p]

{MyFun1[1, x], MyFun2[2, x]}

q = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {-1}]

{{2, 2, 0}, {3, 2, 0}}

Extract[expr, q]

{MyFun1, MyFun2}

Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

expr = 2 x + x^2 MyFun1[1, x] + x^3 MyFunction[2, x];

p = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {}, Heads -> False]

{{2, 2}, {3, 2}}

Extract[expr, p]

{MyFun1[1, x], MyFun2[2, x]}

q = Position[expr, x_ /; StringMatchQ[ToString[x], "My*"], {-1}]

{{2, 2, 0}, {3, 2, 0}}

Extract[expr, q]

{MyFun1, MyFun2}