Sublime Forum

Regular Expressions Not Working Correctly

#1

I have a snippet with a regular expression in it. I ported it from TextMate where it did (and does) work, but it doesn’t not work in Sublime Text 2.

Here’s the snippet:

<?php \$${2:${1/:alpha:]]+|( )/(?1:_:\L$0)/g}} = new Area("${1:Main}"); \$$2->display(\$c); ?>

When activated, it selections Main, and if I were to type something like, “Sidebar Footer,” the expected outcome (and actual outcome in TextMate) is:

<?php $sidebar_footer = new Area("Sidebar Footer"); $sidebar_footer->display($c); ?>

But the actual output in Sublime is:

<?php $sidebar_ footer = new Area("Sidebar Footer"); $sidebar_ footer->display($c); ?>

The extra spaces shouldn’t be there. I consider myself pretty good with regular expressions, but this is probably one of the extremely few times I’ve had to use the syntax with the search and replace in one line.

Basically Sidebar Footer/:alpha:]]+|( )/(?1:_:\L$0)/g is not being evaluated correctly. I am 80ish% sure it’s correct, and Sublime is wrong here, or else uses a different parser than TextMate does?

Specifically, it seems to be prepending the space with an underscore instead of replacing the space with an underscore.

Thanks,
CWSpear

0 Likes