正则表达式 Spotfire 版本计算反向出现次数

huangapple go评论85阅读模式
英文:

Regular Expression Spotfire flavor counting occurrences backwards

问题

我有包含任意数量的'-'的输入字符串,我需要一个正则表达式,以返回从输入的开头到倒数第二个'-'的位置,如果少于2个'-'则返回输入的副本。

例如:
输入: "VS-TEST1-tbl0-max" 输出: "VS-TEST1"
输入: "VSTEST1-tbl0-max" 输出: "VSTEST1"
输入: "AllOneWord" 输出: "AllOneWord"
输入: "AllOneWord-VS" 输出: "AllOneWord-VS"

英文:

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.

答案1

得分: 0

你所需的转换等同于用空字符串替换最后两个块(包括分隔符)。匹配包括分隔符的两个末尾块的正则表达式是 (-[^-]*){2}$

用于此目的的函数是 RXReplace

使用示例:

RXReplace('VS-TEST1-tbl0-max', '(-[^-]*){2}$', '') -> 'VS-TEST1'
英文:

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'

huangapple
  • 本文由 发表于 2023年1月9日 04:35:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定