MathGroup Archive 2002

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

Search the Archive

Re: Question about Replace

  • To: mathgroup at
  • Subject: [mg35698] Re: [mg35670] Question about Replace
  • From: "Julio Vera" <jvera at>
  • Date: Fri, 26 Jul 2002 04:16:48 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at


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.


e^x + x + w x + z/x

----- Original Message -----
From: "Xuguang Zhang" <xzhang2 at>
To: mathgroup at
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

  • Prev by Date: Re: Slow iteration in a functional program
  • Next by Date: Re: MatrixForm Oddity
  • Previous by thread: Question about Replace
  • Next by thread: Re: Question about Replace