在DOORS DXL中,如何使用正则表达式确定字符串是否以数字开头? [英] In DOORS DXL, how do I use a regular expression to determine whether a string starts with a number?

查看:194
本文介绍了在DOORS DXL中,如何使用正则表达式确定字符串是否以数字开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定字符串是否以数字开头-我尝试了以下操作但无济于事:

I need to determine whether a string begins with a number - I've tried the following to no avail:

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

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

I'm new to DXL and Regex - what am I doing wrong?

推荐答案

仅在字符串的开头需要插入符号来表示匹配项.我添加了加号以匹配所有数字,尽管您可能不需要这种情况.如果您只是从头开始寻找数字,并且不在乎后面是否有任何内容,那么您就不需要了.

You need the caret character to indicate a match only at the start of a string. I added the plus character to match all the numbers, although you might not need it for your situation. If you're only looking for numbers at the start, and don't care if there is anything following, you don't need anymore.

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

这篇关于在DOORS DXL中,如何使用正则表达式确定字符串是否以数字开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆