如何从字符串中获取id值

本文关键字:获取 id 字符串 | 更新日期: 2023-09-27 18:08:11

我有一个字符串如下:

string st = [Task id=9 uniqueID=10 name=Projeect Information]

我想从上面的字符串中获得id的值,我使用了代码:

st.Split(' ')[1].Split('=')[1] // return 9

但我感觉不太好。我想使用正则表达式来获取id的值。如果你知道,请分享你的想法。

感谢

如何从字符串中获取id值

使用后备:

(?<=id=)'d+

演示


C#示例代码(Regex.Match(:

Regex.Match(@"(?<=id=)'d+", st);

怎么样:

'bid=('d+)

id将在组1中。

使用此正则表达式(?<='w=)[^ ]+