1

I thought I was getting the hang of making my own snippets, but I can't figure out to transform a tab stop so that 'Ignore/Before/Slashes/Oh Hey Text' becomes 'OhHeyText'.

so far I have this

${4/.*\\/(.+$)/$1/g}

or

${4/\\s//g}

But I can't figure out how to chain the transforms together. I've read through 5 or 6 posts here on SO already, but I'm having a lot of trouble grokking the actual transformation syntax, and extrapolating that to my use case.

Thanks for any help you can give!

Ben Wong
  • 339
  • 1
  • 8

1 Answers1

1

You can use

"${TM_DIRECTORY/^.*[\\/\\\\]|\\s+//g}"

See the regex demo. Details:

  • ^.*[\/\\] - start of string, any zero or more chars other than line break chars as many as possible, and then / or \
  • | - or
  • \s+ - one or more whitespaces.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Man, you must dream in Regex, thanks a lot! I will add that this example actually did help me think about it in a new way (and wasn't just a copy/paste/forget answer) – Ben Wong Feb 11 '22 at 20:46
  • @BenWong I forgot to add that `g` is important here, it makes the regex engine replace *all* found occurrences in the string. Otherwise, the alternation would not help. – Wiktor Stribiżew Feb 11 '22 at 21:01
  • If you don't mind, for the sake of my learning, how would you extend this regex alternating strategy to include a requirement that wasn't about deleting, like you had to keep the first letter after a slash and make it capitalized (as a silly example). – Ben Wong Feb 12 '22 at 03:07
  • 1
    @BenWong If the task is to uppercase the first char after last `/`, you could use `"${TM_DIRECTORY/^.*(?=[\\/\\\\])|[\\/\\\\]([^\\/\\\\])(?=[^\\/\\\\]*$)|\\s+/${1:/upcase}/g}"` – Wiktor Stribiżew Feb 12 '22 at 11:06