-1

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?

AndersTornkvist
  • 2,610
  • 20
  • 38
Naga
  • 9
  • 2

1 Answers1

0

You could try

anydate\b(?<op>(between|contains))\b(?<first>[0-9]*)\b(?<op2>(~~|and))\b(?<second>[0-9]*)

edit Guessing at whats needed but:

(?<func>\w+)\b(?<op>(between|contains))\b(?<first>\w+)\b(?<op2>(~~|and))\b(?<second>\w+)
FlyingStreudel
  • 4,434
  • 4
  • 33
  • 55