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!
-
What is in your tabstop 4? Text you enter, some filePath, etc.?Mark– Mark2022年02月11日 20:41:32 +00:00Commented Feb 11, 2022 at 20:41
1 Answer 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.
answered Feb 11, 2022 at 20:27
Wiktor Stribiżew
631k41 gold badges501 silver badges629 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
Ben Wong
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)
Wiktor Stribiżew
@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.Ben Wong
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).
Wiktor Stribiżew
@BenWong If the task is to uppercase the first char after last
/, you could use "${TM_DIRECTORY/^.*(?=[\\/\\\\])|[\\/\\\\]([^\\/\\\\])(?=[^\\/\\\\]*$)|\\s+/${1:/upcase}/g}"Explore related questions
See similar questions with these tags.