[R U a genius?] .Net regular expressions (csharp)

  • Thread starter Thread starter Daniel Dupont
  • Start date Start date
D

Daniel Dupont

Hi there,
I want to test a String. This string must be made of
- 8 numbers
- then a single underscore
- and then 6 numbers

Can anybody tell me what can be the right .Net pattern ?

String sample :
"20041224_235959" (latest christmas)
"20011109_140000" (9/11 crime - CET)
"19891009_180000" (Berlin wall of shame)
"00001224_235959" (That's a joke ! ;-)

Thanks,
 
Hi there,
I want to test a String. This string must be made of
- 8 numbers
- then a single underscore
- and then 6 numbers

Can anybody tell me what can be the right .Net pattern ?

String sample :
"20041224_235959" (latest christmas)
"20011109_140000" (9/11 crime - CET)
"19891009_180000" (Berlin wall of shame)
"00001224_235959" (That's a joke ! ;-)

Thanks,

Ok that was not a matter of beeing a genius ;-))

Regex r = new Regex(@"[\d]{8}_[\d]{6}");
if (r.IsMatch(textBox1.Text,0) ){
label1.Text="match";
}else{
label1.Text="NO match !";
}
regards,
 
How about?

[0-9]{8}_[0-9]{6}

Daniel said:
Hi there,
I want to test a String. This string must be made of
- 8 numbers
- then a single underscore
- and then 6 numbers

Can anybody tell me what can be the right .Net pattern ?

String sample :
"20041224_235959" (latest christmas)
"20011109_140000" (9/11 crime - CET)
"19891009_180000" (Berlin wall of shame)
"00001224_235959" (That's a joke ! ;-)

Thanks,


--
Texeme
http://texeme.com

incognito () Updated Almost Daily
http://kentpsychedelic.blogspot.com
 
Back
Top