Regular expression format
-
Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....
-
Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....
chandler83 wrote:
([0-9]+d )?([
Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
chandler83 wrote:
([0-9]+d )?([
Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Christian Graus wrote:
Regex re=new Regex("^([0-9]+[dhms])$");
Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$ But that would still be wrong, because it wouldn't preserve the order of d,h,m,s. The original Regex at least ensures the correct order of d, then h, then m, then s.
Christian Graus wrote:
Any number of digits
Just to not confuse the thread opener: it acutually meast at least one digit + = one or more * = zero or more ? = optional character, group regards
-
Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....
-
chandler83 wrote:
([0-9]+d )?([
Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
thts perfect........ thank u very much Christian Graus...
-
Christian Graus wrote:
Regex re=new Regex("^([0-9]+[dhms])$");
Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$ But that would still be wrong, because it wouldn't preserve the order of d,h,m,s. The original Regex at least ensures the correct order of d, then h, then m, then s.
Christian Graus wrote:
Any number of digits
Just to not confuse the thread opener: it acutually meast at least one digit + = one or more * = zero or more ? = optional character, group regards
Greeeg wrote:
Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$
No, you're wrong. I said if the regex is intending to find ONLY ONE group out of the four ( not any of the four groups, in that order ), then the regex I provided would be a substitute.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog