Re: Regex question




"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message
news:494d099a$0$90276$14726298@xxxxxxxxxxxxxxxxxx
tshad wrote:
"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message
news:494c4fb2$0$90274$14726298@xxxxxxxxxxxxxxxxxx
tshad wrote:
This is really a regex question.

I am wonding if anyone knows a good Regex expression that would pull a
valid date from a string.

I have used:

strValue = Regex.Replace(valueIn, @"[^\d/]", "");

which works most of the time.

But I have some cases where I have strings like:

05/07/08(-4%)
09/19/08 DOM 55
09/19/2008 DOM 53
FOR 09/15/08 -23
For inspiration see below.

That looks good. Would that handle 1 and 2 digits for days and months
and 2 and 4 for years?

private static readonly Regex re = new
Regex(@"\d{2}/\d{2}/\d{2}", RegexOptions.Compiled);

@"\d{1,2}/\d{1,2}/\d{2,4}"

is more flexible.

Great. That really helps.

Thanks,

Tom


Arne



.



Relevant Pages

  • Re: getAttribute question
    ... oddity with IE that getAttributereturns an empty string if the ... HTML specification, ... appropriate places in the HTML 4 and DOM HTML specifications. ...
    (comp.lang.javascript)
  • Re: Regex question
    ... I am wonding if anyone knows a good Regex expression that would pull a valid date from a string. ... 09/19/2008 DOM 53 ...
    (microsoft.public.dotnet.languages.csharp)
  • Mixed SAX and DOM processing: echoing with occassional changes.
    ... assembling them into a DOM as I hit closing elements. ... public void startElement(final String uri, final String localName, ... final String qName, ... // Pass off to serialization. ...
    (comp.lang.java.programmer)
  • Re: XSLT Transformation in Javascript
    ... I can get a transformed XML string no problem. ... and then grab the child nodes of the in memory div element I don't think there is a way to get from a string to nodes. ... appended to a child in any DOm compliant browser universally. ...
    (microsoft.public.scripting.jscript)
  • Re: Encodings of javascript
    ... How does javascript know that the string it is given is encoded using ... How does the string get inserted into the HTML with UTF-8 encoding? ... The DOM API uses the DOMString type, ... If the browser is Open Source, you can UTSL to confirm that. ...
    (comp.lang.javascript)

Loading