Negative Offsets to Indicate Reverse List Searches?

I might ask that the optional OFFSET parameter in such functions as RemoveListItem accept a NEGATIVE value to indicate a search that should go backward along the list. I could then parse backward to remove the DATESTAMP in the string below without having to query the randomly unknown number of items in the string. The use of INF does not seem to work here?

newstring = RemoveListItem(0,"SomeFileName_withthisblabla_DATESTAMP","_",-1)
// newstring <-- "SomeFileName_withthisblabla"


Yes. I'll try again. It seemed I tried with wildcards "_*" as the ending string with no luck. In my case, DATESTAMP is not a fixed value.


In spite of its name (which tells you what the author thought you would use it for) the ParseFilePath() function is useful for any sort of list. You would use something like

newstring = ParseFilePath(1,"SomeFileName_withthisblabla_DATESTAMP", "_", 1, 0)

I use this frequently for parsing subwindow names and I have used it for just the sort of thing you are talking about.

It's possible that others here at WaveMetrics might object, saying that it really is intended for file paths, but in fact it is so generally written that it is useful for a whole host of things.

You could use something like below for removing a regex from a end of a string.

/// @brief Remove the given reguluar expression from the end of the string
/// In case the regular expression does not match, the string is returned unaltered.
/// See also `DisplayHelpTopic "Regular Expressions"`.
Function/S RemoveEndingRegExp(str, endingRegExp)
    string str, endingRegExp

    string endStr

    if(strlen(str) == 0 || strlen(endingRegExp) == 0)
        return str

    SplitString/E="(" + endingRegExp + ")$" str, endStr

    return RemoveEnding(str, endStr)


Hi Thomas,

To prove I follow the discussions on the board  carefully, I will quote I think from John Weeks "I solved the problem using regex and now I have two problems."


Which was if I believe correctly his response to my own proposal to use REGEX to solve a different problem.