My regex for a VS Code Snippet is not working

I have some files with names starting with core- and following one or more words separated by hyphen, like this:

core-query
core-query-pagination
core-query-pagination-numbers

I'm creating a VS Code Snippet to transform the file name to get this result:

QUERY
QUERY PAGINATION
QUERY PAGINATION NUMBERS
  1. Remove core-
  2. Replace - with
  3. Capitalize every word

What I've got so far is this:

"${TM_FILENAME_BASE/([^-]+)(-*)/${1:/capitalize}${2:+ }/g}"

Output:

Core Query Pagination Numbers

Upvotes: 0

Views: 30

Answers (1)

Ahmad Ismail
Ahmad Ismail

Reputation: 13952

Please check if the following works for you:

${TM_SELECTED_TEXT/(^core-)|(-)|([a-z]*)/${2:+ }${3:/upcase}/gm}

You can use the following if you do not need to remove the -.

${TM_SELECTED_TEXT/^core-(.*)/${1:/upcase}/gm}

Upvotes: 0

Related Questions