Regex - First steps

  • Thread starter Thread starter mick
  • Start date Start date
M

mick

Just started learning about Regex so I only understand at a very basic
level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick
 
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Hans Kesting
 
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Hans Kesting
 
Hans Kesting said:
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic
level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)

Thanks,

mick
 
Hans Kesting said:
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic
level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)

Thanks,

mick
 
Another way would be

new Regex(@"\(\d{2}(_\d{2}){0,3}\)")

where \d is a shorthand for any digit.
and {2} means exactly two times.

Ethan

mick said:
Hans Kesting said:
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic
level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)

Thanks,

mick
 
Another way would be

new Regex(@"\(\d{2}(_\d{2}){0,3}\)")

where \d is a shorthand for any digit.
and {2} means exactly two times.

Ethan

mick said:
Hans Kesting said:
mick explained on 15-5-2009 :
Just started learning about Regex so I only understand at a very basic
level.
What I would like to know is, is there an easier way to check for the
following
four patterns or do I need to do four checks -

(xx)
(xx_xx)
(xx_xx_xx)
(xx_xx_xx_xx)

xx = numbers
brackets are included in patter.

eg. "(23_24_25)"
"(10_11)"
etc

mick

I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)

Thanks,

mick
 
Ethan Strauss said:
I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)
Another way would be

new Regex(@"\(\d{2}(_\d{2}){0,3}\)")

where \d is a shorthand for any digit.
and {2} means exactly two times.

Ethan

Nice one Ethan, thanks for your help.

mick
 
Ethan Strauss said:
I think this will work:

new Regex(@"\([0-9][0-9](_[0-9][0-9]){0,3}\)")

the @, so that the \ is not special
\( for a literal "("
[0-9] a single digit
(_[0-9][0-9]){0,3} the pattern "_##" repeated 0 - 3 times

Brilliant. You should have seen the nonesense I produced:-)
Another way would be

new Regex(@"\(\d{2}(_\d{2}){0,3}\)")

where \d is a shorthand for any digit.
and {2} means exactly two times.

Ethan

Nice one Ethan, thanks for your help.

mick
 
Back
Top