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