0
$\begingroup$

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)?

$\endgroup$
3
  • 2
    $\begingroup$ at least closely related: 75294 $\endgroup$
    – Kuba
    Commented Feb 8, 2017 at 9:20
  • $\begingroup$ @Kuba yep. I will flag it as duplicate. $\endgroup$
    – mattiav27
    Commented Feb 8, 2017 at 9:25
  • $\begingroup$ @Kuba I forgot my own duplicate. :-( $\endgroup$
    – Mr.Wizard
    Commented Feb 8, 2017 at 9:29

1 Answer 1

3
$\begingroup$
{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

$\endgroup$
1
  • 1
    $\begingroup$ +1 ! or use your approach with a pattern test {x1,x2,x3,y1,y2}/._Symbol?(StringMatchQ[SymbolName[#], "x*"] &) -> 0 $\endgroup$
    – Ali Hashmi
    Commented Feb 8, 2017 at 9:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.