[英]regular expression of 3 groups check
I'd like a group of 3 values in the following regular expression and input string 我想要在以下正则表达式和输入字符串中包含3个值的组
With the help of the SO experts this is what I have: 在SO专家的帮助下,这就是我所拥有的:
string item = "strawb bana 1 10 1.93";
string pattern = @"(?<str>[\w\s]*)(?<qty>\s\d*\s)(?<num>\d*\.\d+)";
Basically, 基本上,
The first value is going to be the product description. 第一个值将是产品说明。 I put a 1 on the end just in case the description has a number in it.
如果描述中有数字,我会在末尾加一个1。
The second value is the quantity. 第二个值是数量。
The third value is price. 第三个值是价格。
Does this look correct? 这看起来正确吗? Might I be missing other cases?
我可能会错过其他情况吗?
Result should be the following 结果应为以下
Group 1 = "strawb bana 1"
Group 2 = "10"
Group 3 = "1.93"
It looks like you forgot to include digits in your first match. 您似乎忘记了在第一场比赛中输入数字。
string item = "strawb bana 1 10 1.93";
string pattern = @"(?<str>[\w\s]*)(?<qty>\s\d*\s)(?<num>\d*\.\d+)";
Should be: 应该:
string item = "strawb bana 1 10 1.93";
string pattern = @"(?<str>[\w\s\d]*)(?<qty>\s\d*\s)(?<num>\d*\.\d+)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.