2

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!

asked Feb 11, 2022 at 19:45
1
  • What is in your tabstop 4? Text you enter, some filePath, etc.? Commented Feb 11, 2022 at 20:41

1 Answer 1

2

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.
answered Feb 11, 2022 at 20:27
Sign up to request clarification or add additional context in comments.

4 Comments

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)
@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.
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).
@BenWong If the task is to uppercase the first char after last /, you could use "${TM_DIRECTORY/^.*(?=[\\/\\\\])|[\\/\\\\]([^\\/\\\\])(?=[^\\/\\\\]*$)|\\s+/${1:/upcase}/g}"

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.