英文:
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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论