[TxMt] Snippet regex transformation help

Ed Singleton singletoned at gmail.com
Thu Oct 5 15:34:47 UTC 2006


On 10/5/06, Allan Odgaard <throw-away-1 at macromates.com> wrote:
> On 5. Oct 2006, at 16:38, Ed Singleton wrote:
>
> > I'm trying to use a regex transformation in a snippet that will
> > convert the first letter of a word to uppercase and convert underscore
> > _ followed by a letter to a space and an uppercase letter.
> >
> > eg:
> >
> > field_name > Field Name
> > long_field_name > Long Field Name
>
> I think this should do: ${1/([a-z]+)(_)?/\u$1(?2: )/g}

Thanks!  Turns out I was looking at it backwards.  I was trying to
look for a single letter preceded by the beginning of the word or an
underscore, rather than just any group of letters with an optional
underscore after.

> > [...] Is there a collection of regexes for transforming between the
> > main
> > cases?
>
> Nope -- I've been wanting to start sort of a recipes section in the
> manual, sounds like these would be good examples to have there :)

I've been playing with snippets a lot recently (best things ever), and
the one thing I've really missed is a snippets bundle.  I edit my
snippets in Textmate using the "edit in textmate" thing and there's
quite a few handy commands I could do with (like "renumber tab stops"
and stuff) and snippets to insert .  I may try and work out how to
write the commands and stuff if no one else does soon.

Ed



More information about the textmate mailing list