I have a script file containing 1000 lines of data and some of the lines contain some date string in the form of dd/mm/yyyy hh:mm:ss format. My objective is to find out the lines which contain a date of the following p开发者_Go百科attern
"Value=10/08/2010 13:39:37", ENDITEM,
Some example lines which contains dates in the script are
"Name=s_1_1_81_0", "Value=10/08/2010 13:39:37", ENDITEM,
// {Siebel_Parse_Web_Page72_S_BC2_S40_R02_F30} = "07/27/2010" (Some Date)
Number0*12*Install Date19*08/24/2010 00:00:0015*Unit of Measure9*Per Month19*To Service
I want to find out ONLY those lines similar to the first example not the other ones, i.e. the lines containing date string which starts with "Value= and ends with ",
I want the code in C# please.
It looks like you want lines that contains a match of the following pattern:
"Value=\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}", ENDITEM,
As a @-quoted C# string literal, it's:
@"""Value=\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}"", ENDITEM,"
The \d
is the character class shorthand for the digit character class. The {n}
is finite repetition specifier. Thus, \d{4}
matches exactly 4 digits.
You can make the pattern less or more specific, e.g. year 9999
not being matched, etc, but it's probably not worth the effort performing numeric range check in regex.
See also
- regular-expressions.info/Numeric Ranges
Related questions
- Regex: why doesn’t
[01-12]
range work as expected?
精彩评论