I don’t entirely understand what you are trying to do.
If you want to get the first letter of the filename capitalized, along with the first letter after every underscore, you can use the following:
class ${1:${TM_FILENAME/(?:^|_)([a-z])|\.rb|(^$)/\u\1(?2:Controller)/g}} < ApplicationController
end.
-
(?:^|_)
non capture group, start of string or _
- followed by
([a-z])
capture group 1, lower case a-z
-
|\.rb
or .rb
-
|(^$)
or capture group 2, no filename (i.e. file not saved yet)
replace with:
-
\u\1
upper case capture group 1
- in the
.rb
case, capture group 1 will be empty, and therefore will be replaced with nothing
-
(?2:Controller)
if capture group 2 matched, insert the text Controller
File name customers_controller.rb
becomes CustomersController
, shipping_lists_controller.rb
becomes ShippingListsController
, branches_controller.rb
becomes BranchesController
, and an unsaved file will just become Controller
.
Does that help?