How to Remove N repeating, leading or trailing characters/strings

Hi All,

I am trying to find a filter to remove only one or more leading characters from a string such as\\\\one\two\three.four would become one\two\three.four, ie removes N \ leading characters.

This comes about due to irregularities in file URI’s

It would be nice if this could be extended to allow us to also replace \\\\, \\\, \\ or \ with only \.

  • We could use this to remove N items and leave only one

Solved it myself so made this topic into a “How To”.

{{{ [<string>split[/]!is[blank]join[/]] }}}

  • This removes the character as many times as it exists, but ignores cases where the result is blank, which is when one character preceeds another, then join them back with the same character. It also results in reducing all repeated characters to one.

What could I call this if I made it into a custom operator? It removes repeats and leading and trailing characters.

  • Perhaps trim.repeats?

So now I have a 5.3.0 Function as operator

\function trim.repeats(trim) [split<trim>!is[blank]join<trim>]

{{{ [[///I:////folder/]trim.repeats[/]] }}}

Post Script:

If you only wanted to trim leading and trailing you can use the trim operator

{{{ [[///I:////folder/]trim[/]] }}}
1 Like