gpt4 book ai didi

regex - 在 DOORS DXL 中,如何使用正则表达式来确定字符串是否以数字开头?

转载 作者:行者123 更新时间:2023-12-04 04:39:34 24 4
gpt4 key购买 nike

我需要确定一个字符串是否以数字开头 - 我尝试了以下方法无济于事:

if (matches("^[0-9].*)", upper(text))) str = "Title"""

我是 DXL 和 Regex 的新手——我做错了什么?

最佳答案

您需要插入字符来指示仅在字符串开头的匹配项。我添加了加号以匹配所有数字,尽管您可能不需要它来适应您的情况。如果您只是在开始时寻找数字,而不关心后面是否有任何内容,那么您就不再需要了。

string str1 = "123abc"
string str2 = "abc123"

string strgx = "^[0-9]+"
Regexp rgx = regexp2(strgx)

if(rgx(str1)) { print str1[match 0] "\n" } else { print "no match\n" }
if(rgx(str2)) { print str2[match 0] "\n" } else { print "no match\n" }

上面的代码块将打印:
123
no match

关于regex - 在 DOORS DXL 中,如何使用正则表达式来确定字符串是否以数字开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com