Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern matching question and answer

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63065] Re: Pattern matching question and answer
  • From: bghiggins at ucdavis.edu
  • Date: Tue, 13 Dec 2005 03:40:46 -0500 (EST)
  • References: <dnir79$9ur$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Matt, Here is a variation on your solution using RegularExpression:

Define a test function:

TestQ := StringMatchQ[ToString[#], RegularExpression["[xyz]\\d"]] &

Cases[expr, Times[p_?TestQ, _]]

{x^2*x0, y^2*y0, z^2*z0}

It a simple matter to extend the pattern in the test function to handle
longer identifiers using the power of regex.

Cheers,

Brian


  • Prev by Date: Re: color points in TableForm
  • Next by Date: Re: How to compute this sum?
  • Previous by thread: Pattern matching question and answer
  • Next by thread: Re: Pattern matching question and answer