正则表达式太贪婪了
我需要验证一个范围。 输入采用以下格式:
string example1 = "anydate between 20100101 ~~ 20100101";
string example2 = "anydate between 20100101 and 20100101";
string example3 = "docid between 1 ~~ 2";
我使用以下正则表达式:
\b(\w)*(?<operator>Between|contains)\b(?<prefix>.*).*?(?<OP>~~|and)[ ]?\b(?.*)\b
当用户输入“20100101 ~~ 20100101和test1之间的任何日期”
时,它失败并捕获直到test1
。
如何让我的正则表达式不那么贪婪并且只捕获20100101
?
I have requirement to validate a range.
The input is in the following format:
string example1 = "anydate between 20100101 ~~ 20100101";
string example2 = "anydate between 20100101 and 20100101";
string example3 = "docid between 1 ~~ 2";
I'm using the following regex:
\b(\w)*(?<operator>Between|contains)\b(?<prefix>.*).*?(?<OP>~~|and)[ ]?\b(?.*)\b
When user inputs "anydate between 20100101 ~~ 20100101 and test1"
it is failing and it captures till test1
.
How to make my regex less greedy and only caputure till 20100101
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
编辑猜测需要什么,但是:
You could try
edit Guessing at whats needed but: