Let's says I have this code:
is.numeric(mean(mtcars$mpg))
Let's says I highlight the code and press CMD+E to use code as find. What regular expression can I use to strip the outer function? So the replacement code would be mean(mtcars$mpg)
Cheers Ross
On 21 Nov 2013, at 17:43, Ross Ahmed wrote:
[…] What regular expression can I use to strip the outer function? So the replacement code would be mean(mtcars$mpg)
I think this questions is underspecified. What exactly are your requirements for how the functions look? What is your goal here (e.g. to run a global search and replace on a specific function call wrapped by an arbitrary other function call and strip the other)?
Perhaps the whole question didn't get posted
I would select is.numeric(mean(mtcars$mpg)), hit use as find, and use a regular expression to replace is.numeric(mean(mtcars$mpg)) with mean(mtcars$mpg).
In another instance, I would select is.character(length('a', 'b')), hit use as find, and use a regular expression to replace is.character(length('a', 'b')) with length('a', 'b').
In another instance, I would select summary(lm(y ~ x)), hit use as find, and use a regular expression to replace summary(lm(y ~ x)) with lm(y ~ x).
Ross
On 22 Nov 2013, at 02:19, "Allan Odgaard" mailinglist@textmate.org wrote:
On 21 Nov 2013, at 17:43, Ross Ahmed wrote:
[…] What regular expression can I use to strip the outer function? So the replacement code would be mean(mtcars$mpg)
I think this questions is underspecified. What exactly are your requirements for how the functions look? What is your goal here (e.g. to run a global search and replace on a specific function call wrapped by an arbitrary other function call and strip the other)?
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 22 Nov 2013, at 13:57, Ross Ahmed wrote:
Perhaps the whole question didn't get posted
I would select is.numeric(mean(mtcars$mpg)), hit use as find, and use a regular expression to replace is.numeric(mean(mtcars$mpg)) with mean(mtcars$mpg) […]
Assuming the outer function name is only word characters and inner function is word characters or the dollar sign, you can search for: \w+(([\w$]+(.*?)))
Then replace with $1 (capture register one).
I would recommend that you study regular expressions and also TextMate’s format strings, for the more TextMate specific stuff, here are some useful links:
- 1.x manual: http://manual.macromates.com/en/regular_expressions#replacement_string_synta... - extended 2.0 grammar: http://manual.textmate.org/references.html#format-string - blog post example for 2.0: http://blog.macromates.com/2012/nested-replacements/