[TxMt] regex question

Andy Armstrong andy at hexten.net
Tue Feb 21 19:27:51 UTC 2006


On 21 Feb 2006, at 18:50, Oliver Taylor wrote:
> Matching the 2nd line (but not the 5th): I want to match any line  
> that begins and ends with a parenthetical ... ^\(.*\)$ ... but only  
> when the line is directly preceded by a line of all capitol letters,

This

^[A-Z]+\n\([^\)]*\)$

does the trick. Broken down

^                      matches start of the first line
  [A-Z]+                matches a run of one or more upper case letters
        \n              matches the end of the first line
          \(            matches the opening parenthesis
            [^\)]*      matches a run of zero or more characters  
matching
                        anything apart from a closing parenthesis
                  \)    matches the closing parenthesis
                    $   matches the end of the second line

If you want to capture the upper case letters (so you can refer to  
them as $1 in the replacement pattern) add brackets like this:

^([A-Z]+)\n\([^\)]*\)$

If you want to capture the contents of the brackets add brackets like  
this:

^[A-Z]+\n\(([^\)]*)\)$

-- 
Andy Armstrong, hexten.net




More information about the textmate mailing list