How to make a PCRE TextMate snippet
Because I’ll Forget #1099:
Problem
Create a TextMate snippet that will build a label for a given input textbox using Human Cased words from an underscored name attribute.
Solution
TextMate snippets support Perl Regexps which is a beautiful, albeit scary, thing. Start by making the label in direct relation to the input tag’s “name.” The label’s “for” attribute should stay the same as the input’s “name,” but the actual text displayed between the label should be in Human format (ie: Uppercase first letter only, and spaces instead of “_”). Heres the final result:
<label for="$2">${2/([a-z]){1}([a-z0-9]+)|(_)/(?3: :\U$1\L$2)/gi}</label> <input type="${1:text}" name="${2:input}"${TM_XHTML}>
$0
*The line broke early, where the substitution for the “_” to ” ” should be (?3: :{rest of the code here}
There is probably a more elegant solution, but this works for now.







Add Yours
YOU