View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.programming
Lars-Åke Aspelin[_2_] Lars-Åke Aspelin[_2_] is offline
external usenet poster
 
Posts: 913
Default Regular Expression Help on syntax

On Sat, 09 Jan 2010 22:50:16 -0500, Ron Rosenfeld
wrote:

On Sat, 09 Jan 2010 23:47:45 +0100, Lars-Åke Aspelin
wrote:

In order to get a proper match I have to use the \ character before
the / characters in the Format function, like this

sURLdate = Format(CDate("1/1/2010"), "\/yyyy\/m\/d\/")

Maybe this has something to do with the Regional and Language
settings.


I don't know. AFAIK, all characters except

[\^$.|?*+()

should get matched literally.

Preceding a character (that has no special meaning) by a backslash ("\") merely
represents a single instance of the second character.

If you type, into the immediate window:

?CDate("1/1/2010")

what is returned?


I also have a question. What is the function of the two \b in the
regexp? I get a match even without them.
And the negative number is also matched.


\b represents a word boundary, or, more specifically, it matches at the
position between a word character (anything matched by \w) and a non-word
character (anything matched by [^\w] or \W) as well as at the start and/or end
of the string (or line) if the first and/or last characters in the string (or
line) are word characters.
--ron


If I write ?CDate("1/1/2010") in the immediate window the following is
returned
2010-01-01

If I write ?Format(CDate("1/1/2010"), "/yyyy/m/d/") the following is
returned
-2010-1-1-

Only if I write ?Format(CDate("1/1/2010"), "\/yyyy\/m\/d\/" the wanted
result
/2010/1/1/
is achieved.

So, with my settings the / character seems to generate a - .
To have a / generated the / has to be escaped with \.

I found the explanation in the Excel help for Format:

"(/) Date separator. In some locales, other characters may be used to
represent the date separator. The date separator separates the day,
month, and year when date values are formatted. The actual character
used as the date separator in formatted output is determined by your
system settings."

And in my settings - (hyphen) is used as the date separator, in
accordance with ISO 8601 extended format
http://en.wikipedia.org/wiki/ISO_8601

Lars-Åke