Re: Question about Replace

*To*: mathgroup at smc.vnet.net*Subject*: [mg35698] Re: [mg35670] Question about Replace*From*: "Julio Vera" <jvera at adinet.com.uy>*Date*: Fri, 26 Jul 2002 04:16:48 -0400 (EDT)*References*: <200207250846.EAA12082@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Heather, This could be a solution. At first, the expression should be treated as text, in which the string "x+y" would be replaced by the string "x". The result should then be turned again into an expression. In[] expre=x+y+z/(x+y)+e^(x+y)+w*x+y Out[] e^(x + y) + x + w x + 2 y + z/(x + y) In[] expretxt="x+y+z/(x+y)+e^(x+y)+w*x+y" Out[] "x+y+z/(x+y)+e^(x+y)+w*x+y" In[] ToExpression[StringReplace[ expretxt,"x+y"->"x"]] Out[] e^x + x + w x + z/x I was not able to keep the expression ordered as entered. In fact, if we manually write the solution, the output obtained is also sorted in this convenient way. I tried Hold and HoldForm. In[]:= sol=x+z/x+e^x+w*x Out[]= e^x + x + w x + z/x Julio ----- Original Message ----- From: "Xuguang Zhang" <xzhang2 at is2.dal.ca> To: mathgroup at smc.vnet.net Subject: [mg35698] [mg35670] Question about Replace > Hello All, > > I have an expression: x+y+z/(x+y)+e^(x+y)+w*x+y.... I want to replace > any (x+y) term by x no matter how the expression looks like. I tried > "/."command. However, it does not work properly. Is there any simple way > of doing this? Thanks. > > -- > Xuguang(Heather) Zhang > > >

**References**:**Question about Replace***From:*xzhang2@is2.dal.ca (Xuguang Zhang)