I'm having a bit of trouble trying to work out if it's possible to have compound regular expressions in a snippet.
Basically, I want to replace all spaces in a tab-stop with hyphens, whilst also lowercasing the whole string -- two things I can happily do separately:
${1/.*/\L$0/} ${1/ /-/\g}
but can't seem to work out if it's possible to do both at the same time. I've tried replacing the tab-stop in one expression with the output from another:
${${1/ /-/\g}/.*/\L$0/}
but it doesn't work. I know it's possible if I create an intermediate tab-stop like this:
${2:${1/.*/\L$0/}} ${2/ /-/\g}
but I don't want to do this as I have no use for the intermediate value.
Any help would be greatly appreciated! Thanks in advance.
Jordan
On 7/6/07, Jordan Harper jordan.harper@cimex.com wrote:
I'm having a bit of trouble trying to work out if it's possible to have compound regular expressions in a snippet.
In general, no. But in your particular example, there is a trick that works:
${1/([^ ])|( )/\L$1(?2:-)/g}
Robin
You're a genius, Robin!
Many thanks.
J
On Jul 6, 2007, at 12:38 PM, Robin Houston wrote:
On 7/6/07, Jordan Harper jordan.harper@cimex.com wrote:
I'm having a bit of trouble trying to work out if it's possible to have compound regular expressions in a snippet.
In general, no. But in your particular example, there is a trick that works:
${1/([^ ])|( )/\L$1(?2:-)/g}
Robin
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 6. Jul 2007, at 12:35, Jordan Harper wrote:
Basically, I want to replace all spaces in a tab-stop with hyphens, whilst also lowercasing the whole string -- two things I can happily do separately:
${1/.*/\L$0/} ${1/ /-/\g}
but can't seem to work out if it's possible to do both at the same time [...]
One workaround is to use conditional insertions, e.g.:
${1/( )|[^ ]+/(?1:-:\L$0)/g}
If we match a space (capture 1), we insert a hyphen, otherwise we insert the match as lowercased.