Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to define a rule that will change a particular type of string to another form. For example:- a string having R1~~"=C"~~"C"("OO|O")~~R2 -> R1~~"C"(O)~~"C"~~R2

share|improve this question
5  
Could you post the complete example (i.e. with original and target string)? Plus, have you looked at the documentation of StringReplace? –  Yves Klett Mar 26 '12 at 12:25
1  
What are the specific transformation rules you want to apply? –  Brett Champion Mar 26 '12 at 16:04
1  
Welcome to Mathematica.SE, learnmathematica. I hope you will learn a lot here. In order to improve your experience here, you can do a lot yourself. Please try to describe your problem as well as you can and also try to show some effort. Your current question looks a bit like "give me the codez fast!" and I'm sure that's not your intention. You will also notice that comments will trickle in pretty quickly after posting a question. Please, make it a habit to check your question regularly, especially in the beginning, and provide feedback as appropriate. –  Sjoerd C. de Vries Mar 26 '12 at 20:22

1 Answer 1

It is not quite clear what you are aiming to do, but perhaps this would work:

StringReplace["r1abc=CxxC(00)r2xyz",
 R1__ ~~ "=C" ~~ x___ ~~ "C(00)" | "C(0)" ~~ R2__ :> 
  R1 <> "C(O)" <> x <> "C" <> R2]

r1abcC(O)xxCr2xyz

share|improve this answer
    
You can have a single RuleDelayed instead of two using ...~~"C(00)" | "C(0)"~~... –  kguler Mar 26 '12 at 12:46
    
@ kguler - already put that in, thanks –  Chris Degnen Mar 26 '12 at 13:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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