Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a regular expression to find the text I want (I wrapped the relevant section in custom tags), and I can do it by hand without much issue, but what I want is a way to automatically find and replace throughout the entire project.

A macro seems like an OK idea, but it would be nice to have a command (to edit and tweak). sed seems like a good bet, but I am pretty unfamiliar with it. I am not so much asking for a complete solution as I am asking for an example that does something close to what I want. I don't really know of a good way to start.

share|improve this question
1  
Did you try Edit -> Find… -> Find in Project…? It's not a one-click solution but it supports regexes, allows you to edit patterns and see what is matched before the actual replace and keeps an history of the previous patterns for you. –  romainl Mar 16 '11 at 9:35
    
yeah, that works. (I dismissed it before because it doesn't macro very well, but it may be the best option.) thanks. –  griotspeak Mar 18 '11 at 14:58
add comment

1 Answer 1

up vote 0 down vote accepted

Use Command+F

Check the box that says Regular expression

In the Find: text field, enter the RegExp that properly captures the character set you want to replace use () to encapsulate the section of the text you want to store in the match data.

In the Replace: text field, type in the replacement regex. You can use $1 up to $9 to use the match data recorded in the 1st to the 9th set of characters captured by () in the Find text field.

This is what I use to automate boring tasks such as replacing newlines with spaces when copying a PDF to a text file

# Find
\n

# Replace
\s

An example with match data would be as follows

# Find
([0-9])\s[+-*/]\s([0-9])

# Replace
$1-$2

... assuming you want to deflate those numeric addition clauses in a source code.

share|improve this answer
add comment

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.