Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to replace a string in a selected region/cell in mathematica notebook/package. I searched but didn' t get any result. I think it' s a quite common feature for editors/programming environments. I guess workbench has this but I don' t have access to a copy.

Maybe now the best option is to use some other editor to do this, is it?

share|improve this question
Why don't you use Find and Replace in the menu Edit, a shorthand (Ctrl+F) ? It helps you to replace whatever you'd like. – Artes May 27 '13 at 12:34
It replaces in the whole notebook by default and doesn' t have an option to replace in the selected region/cell. – xgdgsc May 27 '13 at 12:35
Check again, you can customize replacements, FindNext, FindPrevious, Replace, ReplaceAll, etc. Or maybe you need StringReplace ??? – Artes May 27 '13 at 12:38
Yes, but it's different from replacing in a selected region. Say in the region you have 100 words to confirm replacing and another 100 same world outside this region in the same notebook. It's not practical to use FindNext and Replace only. – xgdgsc May 27 '13 at 12:40
I do the same as @Artes suggested, and yet usually I come across the same problem as you @xgdgsc. What I do is copying the cells that I want to edit to another notebook and then use Find and Replace for the whole [new] notebook. – Sosi May 27 '13 at 13:35
up vote 3 down vote accepted

Many (most?) code editors offer a check box labeled something like "Search in selected text only" (that's the wording used by the Find dialog of the OS X code editor BBEdit), Mathematica's Find dialog, unfortunately, does not support such an option. Until such time as this is rectified by the Mathematica developers, I think the work-around suggested by Sosi is you best opttion

  1. Bring up a new Notebook window
  2. copy the region in which you want to search into the new window
  3. carry out the search and replace there
  4. paste the results back over the selected region in the first notebook.
share|improve this answer
I also use this workaround. Perhaps we can automate it; I've never tried. – Mr.Wizard May 29 '13 at 1:39

Your Answer


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.