Home > database >  Regular Expression Spotfire flavor counting occurrences backwards
Regular Expression Spotfire flavor counting occurrences backwards

Time:01-09

I have input strings with arbitrary number of '-' in them and I need a regular expression to return everything from the start of input to the SECOND FROM THE LAST occurrence of '-' or copy of input if there are less than 2 occurrences

For example: 

            input: "VS-TEST1-tbl0-max" output: "VS-TEST1"
            input: "VSTEST1-tbl0-max"  output: "VSTEST1"
            input: "AllOneWord"        output: "AllOneWord"
            input: "AllOneWord-VS"     output: "AllOneWord-VS"

RegEx language syntax? TIBCO SpotFire one: https://support.tibco.com/s/article/Tibco-KnowledgeArticle-Article-43748

Much thanks to all regexperts.

CodePudding user response:

The transform you desire is equivalent to replacing the last 2 blocks (including the separator) with a blank string. The regex to match only two end blocks including separator is (-[^-]*){2}$

Use the function RXReplace for this purpose.

Usage example:

RXReplace('VS-TEST1-tbl0-max', '(-[^-]*){2}$', '') -> 'VS-TEST1'
  • Related