Re: Simple Regex issue
- From: mdb <m_b_r_a_y@c_t_i_u_s_a__d0t__com>
- Date: Mon, 01 Aug 2005 07:58:54 -0700
"CJ" <cjohns@xxxxxxxxx> wrote in news:1122907960.294291.133150
@g43g2000cwa.googlegroups.com:
> I'm not an expert on regular expressions, but I thought I knew how to
> construct simple ones :-)
>
> I have two very simple regular expresions:
> "|1|(?<dt>\d\d-\d\d-\d\d\d\d).*" and ".*(?<dt>\d\d-\d\d-\d\d\d\d).*"
> With the input string @"|1|01-08-2005 12:57:12", both regular
> expressions match. But the named group dt is correct for the second
> expression (01-08-2005) and just an empty string for the first, which
> just doesn't make much sense to me.
>
>
The | is a special character in a Regex... it means "this or that" (whatever
is before or after the | character.) So in this case, you are probably
matching the empty string before the first | in the first Regex. If you want
those characters to match explicitly, escape them:
\|1\|(?<dt>\d\d-\d\d-\d\d\d\d).*
--
-mdb
.
- Follow-Ups:
- Re: Simple Regex issue
- From: CJ
- Re: Simple Regex issue
- References:
- Simple Regex issue
- From: CJ
- Simple Regex issue
- Prev by Date: Re: Access and Crystal Reports
- Next by Date: Re: Using TempFileCollection
- Previous by thread: Simple Regex issue
- Next by thread: Re: Simple Regex issue
- Index(es):
Relevant Pages
|