473,395 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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,
--
Daniel Dupont
Nov 16 '05 #1
3 1097
Le Thu, 20 Jan 2005 23:31:34 +0100, Daniel Dupont wrote:
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,

--
Daniel Dupont
Nov 16 '05 #2

How about?

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

Daniel Dupont wrote:
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
Nov 16 '05 #3
> Regex r = new Regex(@"[\d]{8}_[\d]{6}");

Or just @"\d{8}_\d{6}"

--

www.midnightbeach.com
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Demetri | last post by:
Lets pretend you have a string array and each element is a sentence. Two of those elements read as follows: 1. The fox escaped from the hound. 2. The fox almost escaped. Now lets say you loop...
6
by: Marc Scheuner [MVP ADSI] | last post by:
Folks, I've started using regular expressions for parsing some data string that come along - works quite nicely, however, as a newbie to RE, I'm still struggling with some special cases: 1) I...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
11
by: Ron Rohrssen | last post by:
Slightly off topic.... How can I write a regex that limits user input to 3 digits in the range of 1-128? I've been trying \d{1,128} but this allows for a match on more than 3 digits. ...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: GHUM | last post by:
I need to split a text at every ; (Semikolon), but not at semikolons which are "escaped" within a pair of $$ or $_$ signs. My guess was that something along this should happen withing csv.py;...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.