Re: Simple Regex issue

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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
.



Relevant Pages

  • Re: Find instance in a string
    ... If there is no 4 character number in the input, an empty string is returned ... The following sites provide a wealth of information on regular expressions. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [opensuse] regexp -- defference between < and  ?
    ... Randall R Schulz wrote: ... With regular expressions, what is the difference between \< and \b? ... There are many grammars for notating them and many varieties of fundamental matching constructs. ... The symbols \respectively match the empty string at the beginning and end of a word. ...
    (SuSE)
  • Re: regular expressions, order of evaluation
    ... inside the first parenthesis, \2 likewise for the 2nd parenthesis. ... most flavours of regular expressions have the ... \1 returns the whole target string, \2 returns the empty string ... Is that statement correct at all, i.e. do indeed most flavours have ...
    (sci.math)
  • [opensuse] regexp -- defference between < and  ?
    ... With regular expressions, what is the difference between \< and \b? ... "The symbols \respectively match the empty string at the beginning and end of a word. ... Nacogdoches, Texas 75961 ...
    (SuSE)
  • Simple Regex issue
    ... I'm not an expert on regular expressions, but I thought I knew how to ... expressions match. ... expression and just an empty string for the first, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)