Search code examples
visual-studio-codevscode-snippets

VS Code snippet - Only keep filename before first dot


I want to keep only the word before the first dot:

user.entity.ts

Current code:

${TM_FILENAME_BASE/([^.]+)/${1:/upcase}/}

Unfortunately, this does only transforms the first part, rather than split it out:

USER.entity

Solution

  • Just use this:

    "body": ["${TM_FILENAME_BASE/([^.]+).*/${1:/upcase}/}"],

    the idea being that your version kept the entity part because it wasn't part of the match - the middle part ([^.]+) in your snuippet.

    Since it wasn't part of the match it goes through unchanged, as it should. So I made it part of the match

    ([^.]+).*

    and now since it isn't part of the replacement, it will be removed.