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 want to replace all the

\caption(.1..)
\caption(.2.)
\caption(.3..)
\caption(.4..)

by

\caption{}

What should I put in the search box?

share|improve this question
    
Should the output be four of "\caption{}" or only one? Should the numbers (1, 2, 3, 4) be extracted and put in the output? –  Peter Mortensen Jun 3 '12 at 7:52
    
TextMate uses the Oniguruma regular expression library. Section 20.3 of the manual has information on the flavour of regular expressions TextMate is using and apparently there are some options in the user interface of TextMate to affect some behaviours of regular expression matching (Ruby, Perl, Java and Oniguruma style). –  Peter Mortensen Jun 3 '12 at 8:26

1 Answer 1

You want to replace

\\caption\(.*\)

with

\caption{}

As simple as that.

You need to have the backtick \ and the parentheses () escaped because they have a special meaning in regular expressions. The .* part matches any character, multiple times. This would match the ..2. substrings.


If you really want to exchange the parentheses to curly braces, you could add a capture group by adding () around the string you want to match, and then reusing it in your replacement:

\\caption\((.*)\)

with

\caption{$1}

The content of your first "caption" is captured in the first register, which we access with $1 again.

Please read the manual on TextMate regular expressions for more: TextMate Manual » Regular Expressions

share|improve this answer

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.