[TxMt] Re: regex in a snippet

Joseph Pecoraro joepeck02 at gmail.com
Tue Mar 17 21:49:08 UTC 2009


How does this work for you:

${1:type here}
RESULT: ${1/(\w+)((?:_|\s)+)?/\L$1\E(?2:_)/g}

Your Code would look like:
<li id="${1/(\w+)((?:_|\s)+)?/\L$1\E(?2:_)/g}"><a href="#">$1</a></li>

Breaking down the regular expression:

	(\w+)                  = This is the first group, $1, matching a word
         ( (?:_|\s)+ )       = This is the second group, $2, matching  
multiple underscores and whitespace

Replacing with:

	\L$1\E               = Lowercase version of $1, the word
         (?2:_)                = If something was found for $2, make  
it a single underscore

This doesn't handle non-word characters like !@#$%'" etc.

Does this point you in the right direction?
- Joseph Pecoraro

On Mar 17, 2009, at 5: 12PM, Saul Rosenbaum wrote:

> Alas I wish there where more basic explanation in the docs
> I can''t for the life of me figure it out..
>
>
>
>
> On Sun, Mar 15, 2009 at 2:14 PM, Oliver Taylor <olivertaylor at me.com>  
> wrote:
> On Sat, Mar 14, 2009 at 1:55 PM, Saul Rosenbaum <saul at visualchutzpah.com 
> > wrote:
>
> > what I'm trying to accomplish is (replacing the spaces with  
> underscores and
> > making it all lowercase)
> > <li id="this_is_a_mixed_case_string_with_spaces"><a href="#">This  
> is a Mixed
> > case String with SPACES</a></li>
>
> Take a look in the TextMate documentation § 7.7 "Transformations".
> You'll find what you're looking for there.
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
>
>
>
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20090317/0117d242/attachment.html>


More information about the textmate mailing list