0

Assume I have an expression caontaining n paramters x1...xn and I wish to what happens to my expression when all of my n parameters are 0. Is there a way to use Wildcard character * (I mean something like x*->0)?

mattiav27
  • 6,677
  • 3
  • 28
  • 64

1 Answers1

3
{x1, x2, x3, y1, y2} /. s_Symbol /; StringMatchQ[SymbolName[s], "x*"] -> 0
{0, 0, 0, y1, y2}

Consider using Context if you need more control, e.g. Pattern match any member of a Context

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 1
    +1 ! or use your approach with a pattern test {x1,x2,x3,y1,y2}/._Symbol?(StringMatchQ[SymbolName[#], "x*"] &) -> 0 – Ali Hashmi Feb 08 '17 at 09:27