<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
			<title>Tagged with "vbscript"</title>
			<link>http://www.addedbytes.com/feeds/tag-feed/</link>
			<description></description>
			<language>en</language>
			<copyright>Web Development in Brighton - Added Bytes 2006</copyright>
			<ttl>120</ttl>
			<item>
				<title>VBScript for Beginners</title>
				<link>http://www.addedbytes.com/articles/for-beginners/vbscript-for-beginners/</link>
				<description><![CDATA[ An introduction to VBScript, one of the languages used to write ASP pages, and tutorial for beginners. <p>ASP stands for Active Server Pages, and is a script engine that runs on IIS web servers (or on Apache servers using ChiliASP). Both IIS and ASP are developed by Microsoft. ASP pages can be written in any one of several scripting languages, the most common one (and default) being VBScript. ASP is a server-side scripting engine that allows you to add interactivity to web pages, process data, interact with databases and so on. It provides similar functionality to languages like Perl and PHP, and like PHP does not need to run within a cgi-bin.</p>

<p>There are several versions of ASP, the current one being ASP 3.0 (ASP.NET is a part of the .NET platform, and we are talking here about "classic" ASP only). VBScript itself is a scripting language and subset of Visual Basic.</p>

<p>VBScript contains seven built-in objects, and you will usually be working with these when writing ASP pages. The objects themselves are:</p>

<ul><li>Application</li><li>ASPError</li><li>ObjectContext</li><li>Request</li><li>Response</li><li>Server</li><li>Session</li></ul>

<p>For this basic introduction, we need only worry about the Response object. The Response object is responsible for sending information back to a user from the server. Any time you write something to a page using VBScript, you will be using the Response object.</p>

<p>ASP pages always end with the extension ".asp", for example "index.asp". Pages that have this extension, on a properly configured server, will be processed by the ASP scripting engine before being returned to the user. Anything within the tags &lt;% and %&gt; is code and will be processed by the engine.</p>

<p>Which brings us neatly to our first piece of code. The first thing you will learn to do with ASP is use it to write a simple string to a web page (the famous "Hello World"). "A string" is a common name for text data.</p>

<code>&lt;html&gt;
&lt;body&gt;
&lt;%
Response.Write("Hello World!")
%&gt;
&lt;/body&gt;
&lt;/html&gt;</code>

<p>Copy and paste the above to an empty text file (for example in Notepad). Save it as "vbscript101.asp", and upload it to a server that supports ASP. When you load the page in a browser, you should see the text "Hello World!". If you do, congratulations! You've finished your first script. If not, it may be that your server does not support ASP - the above should work on any server with ASP support.</p>

<p>What you have done in the above example is write out a normal HTML page, but you have used the ASP scripting engine to write out the text within the page. A good start, but not the most useful of tools so far. Next, we'll learn how to use basic variables.</p>

<p>Variables in VBScript are easy to use, but can be confusing at times. It is always a good idea to name your variables so that you can see easily what they refer to. For example, a variable containing a first name might be called "strFirstName". The "str" tells you it is a string, or text, piece of data. The "FirstName" section tells you what the variable contains - in this case a first name. For a year of birth, you might call a variable "intYearOfBirth" - the int telling you this variable contains an integer.</p>

<p>To use these in a script is reasonably simple. To start with, you need to declare the variable - to tell the ASP engine to create the variable - and then assign a value to it. We then write it out to the page, like so:</p>

<code>&lt;html&gt;
&lt;body&gt;
&lt;%
dim strHelloWorld
strHelloWorld = "Hello World, Again!"
Response.Write(strHelloWorld)
%&gt;
&lt;/body&gt;
&lt;/html&gt;</code>

<p>Note that when you use the variable with the "Response.Write" section, you should not put quotation marks around it. If you do, the script will just write out "strHelloWorld" as text, rather than writing the value you gave it.</p>

<p>The "dim" line is where you declare the variable. The next line is used to assign the value "Hello World, Again!" to the variable. And the third line is used to write it to the page. If you copy and paste the above as before, and upload the new script and open it in a browser, you should now see the text "Hello World, Again!" on the page. If you do, congratulations, you have just finished your second ASP script.</p>

<p>Still, though, not the most impressive piece of interaction on the web. Next though, we're going to write a more complex script. This time, we're going to create a variable, give it a value of the current hour of the day, and display a piece of text based upon whether it is morning or afternoon.</p>

<code>&lt;html&gt;
&lt;body&gt;
&lt;%
dim intHourOfDay
intHourOfDay = hour(now())
if intHourOfDay &lt; 12 then
    Response.Write("Good Morning World!&lt;br&gt;&lt;br&gt;The hour of the day is ") &amp; intHourOfDay
else
    Response.Write("Good Afternoon World!&lt;br&gt;&lt;br&gt;The hour of the day is ") &amp; intHourOfDay
end if
%&gt;
&lt;/body&gt;
&lt;/html&gt;</code>

<p>We start this time by declaring a variable, intHourOfDay. The "int" is to remind us later on, if needed, that this variable contains a number, and the "HourOfDay" tells us that the number itself will be the hour of the day. Next, we grab the current time using the "now()" function, and the current hour by using the "hour()" function on the result (the hour function gives us the hour of a date). At this stage, intHourOfDay will contain a number representing the hour of the current day.</p>

<p>Next, we check the value. If the value is less than 12, we know the current time is morning, and write out an appropriate greeting, followed by the hour of the day (you use the &amp; symbol to write more than one thing to a page at once). Otherwise (else) it is afternoon. The "end if" section at the end tells the ASP scripting engine that the "if" section is over, and to carry on from here as normal.</p>

<p>Now, to use this, you simply need to upload this script, as before, to your web server, and open it in a web browser. Your server may be on a different time zone to you, but you can see what hour of the day it thinks it is underneath the greeting. What you should now see is a greeting of either "Good Morning World!" or "Good Afternoon World!" followed by a blank line, then the hour of the day.</p>

<p>And voila - your first piece of interactive web programming. Congratulations, you've taken your first steps in ASP!</p> <br><br>]]></description>
				<pubDate>Thu, 13 May 2004 09:56:46 +0100</pubDate>
				<guid isPermaLink="false">http://www.addedbytes.com/articles/for-beginners/vbscript-for-beginners/</guid>
				<dc:creator>Dave Child</dc:creator>
				<a href="/feeds/tag-feed/?tags=asp&amp;start=0" class="ditto_tag" rel="tag">asp</a>,<a href="/feeds/tag-feed/?tags=for+beginners&amp;start=0" class="ditto_tag" rel="tag">for beginners</a>,<a href="/feeds/tag-feed/?tags=vbscript&amp;start=0" class="ditto_tag" rel="tag">vbscript</a>
			</item>

			<item>
				<title>VBScript Date Format Functions</title>
				<link>http://www.addedbytes.com/blog/code/vbscript-date-format-functions/</link>
				<description><![CDATA[ Date formatting in VBScript is not quite as powerful as PHP. This function gives you plenty more ways to format dates and times in VBScript with the minimum of effort. <p>VBScript's date formatting doesn't offer a huge number of options compared to PHP's date() function. While it's relatively easy to just write small snippets of code every time you need to format a date a specific way, life would be much easier if there was a function you could call on time and again to do the work for you.</p>

<p>Below, you will find three date format functions, all of which make some use of Unix timestamps, a concept most ASP developers will not be familiar with. Unix timestamps are defined as the number of seconds since the epoch, 00:00:00 01/01/1970, and are a very sensible way to store dates and times in a database, in my opinion. They are very easy to work with, especially when selecting data from a database, and once you are used to them, they can make life much much simpler.</p>

<p><em>NOTE: These functions were updated on the 15th March 2004 to fix a couple of known bugs. In addition, any scripts using these functions may need to be tweaked to take account of your locale. Each locale will use a slightly different date and time format, so please check yours before using these functions, or simply set your locale to UK. To set your locale to UK, you can use the code below:</em></p>

<pre class="php">&lt;%@LANGUAGE=VBSCRIPT" LCID=2057%&gt;</pre>

<p><em>There is also a [url=http://www.microsoft.com/globaldev/reference/lcid-all.mspx]complete list of valid locales[/url] on the Microsoft website, with the values in the right hand column being the ones you will want.</em></p>

<p><em>Finally, the "monthname" function is VBScript is not present in every version, so may need to be defined manually. Please see comments on this article for an example.</em></p>

<p>The first function, UDate(), will convert a normal date into a Unix timestamp. The second function, unUDate(), simply does the reverse, converting any timestamp into a readable date. The last function takes a date and a format string, and returns a formatted date according to what you put into the formatting string.</p>

<h3>UDate()</h3>

<pre class="php">function UDate(oldDate)
    UDate = DateDiff("s", "01/01/1970 00:00:00", oldDate)
end function</pre>

<p>In practice, UDate is very easy to use. For example, if you want to know the current Unix time (the number of seconds since the epoch), you would use something like the following, which would give intCurrent_Unix_Time a value of 1069916571 at the time of writing.</p>

<pre class="php">intCurrent_Unix_Time = UDate(Now())</pre>

<h3>unUDate()</h3>

<pre class="php">function unUDate(intTimeStamp)
    unUDate = DateAdd("s", intTimeStamp, "01/01/1970 00:00:00")
end function</pre>

<p>unUDate is as easy to use as UDate. Simply feed in an integer, and it will return a matching date. It will treat the integer as the number of seconds between the epoch and the desired date, and will return a properly formatted date for normal use in VBScript accordingly.</p>
	
<h3>formatDate()</h3>

<p>Now here's where it starts to get tricky. formatDate is also quite easy to use, but only once you get the hang of how it works. As you can see from the below, formatDate requires two values to be passed to it. The first, format, is a string telling the function how you would like the date formatted, and the second, intTimeStamp, can be either a Unix timestamp (preferred) or a normal VBScript date.</p>

<p>The format of the string is what we want to make use of to lay out our dates exactly as we would like, and perhaps this is best shown with an example. I would like a date displayed on my site in the following format: "7:11am, Thursday 27th November, 2003". In normal VBScript that would be a pain to format - I'd probably just end up giving up and using the normal VBLongTime and VBLongDate to display something similar. I would prefer complete control though...</p>

<p>The format string for formatDate can include a whole selection of characters to represent certain date or time entities. There's a table of the ones included in this function just below here. The format string needs to include these entities where it wants them to be replaced by the correct time or date value. To get the above formatted date and time, then, I could use the following:</p>

<pre class="php">strDateTime = formatDate(<strong>"%g:%i%a, %l %j%O %F, %Y"</strong>, UDate(Now()))</pre>

<p>That looks a lot harder than it actually is. To tell the function we are aiming to replace a specific entity in the string with a time or date element, we use a symbol made up of a percent sign (%) and a letter. It is a case sensitive function, so be careful you form your format strings correctly. Without further ado, here's a list of the entities you can include in the format string (anything in the string that is not an entity from the list below will still be in the string when it has been processed).</p>

<ul><li><span class="listpad">%A</span> - AM or PM</li>
<li><span class="listpad">%a</span> - am or pm</li>
<li><span class="listpad">%m</span> - Month with leading zeroes (01 - 12)</li>
<li><span class="listpad">%n</span> - Month without leading zeroes (1 - 12)</li>
<li><span class="listpad">%F</span> - Month name (January - December)</li>
<li><span class="listpad">%M</span> - Three letter month name (Jan - Dec)</li>
<li><span class="listpad">$d</span> - Day with leading zeroes (01 - 31)</li>
<li><span class="listpad">%j</span> - Day without leading zeroes (1 - 31)</li>
<li><span class="listpad">%H</span> - Hour with leading zeroes (12 hour)</li>
<li><span class="listpad">%h</span> - Hour with leading zeroes (24 hour)</li>
<li><span class="listpad">%G</span> - Hour without leading zeroes (12 hour)</li>
<li><span class="listpad">%g</span> - Hour without leading zeroes (24 hour)</li>
<li><span class="listpad">%i</span> - Minute with leading zeroes (01 to 60)</li>
<li><span class="listpad">%I</span> - Minute without leading zeroes (1 to 60)</li>
<li><span class="listpad">%s</span> - Second with leading zeroes (01 to 60)</li>
<li><span class="listpad">%S</span> - Second without leading zeroes (1 to 60)</li>
<li><span class="listpad">%L</span> - Number of day of week (1 to 7)</li>
<li><span class="listpad">%l</span> - Name of day of week (Sunday to Saturday)</li>
<li><span class="listpad">%D</span> - Three letter name of day of week (Sun to Sat)</li>
<li><span class="listpad">%O</span> - Ordinal suffix (st, nd rd, th)</li>
<li><span class="listpad">%U</span> - UNIX Timestamp</li>
<li><span class="listpad">%Y</span> - Four digit year (2003)</li>
<li><span class="listpad">%y</span> - Two digit year (03)</li></ul>

<p>You can include any of the above in the format string at any point. I would recommend not using a percentage sign if you can help it (except obviously as part of one of the elements above), and in the same vein, using ordinals anywhere except after a number is slightly foolish.</p>

<p>If you would like to see anything else added to the list, above, please email me and I will see what I can do.</p>

<p>The below is the formatDate function itself. To use, simply copy and paste it into a script or include file and call it as above, with whichever format string you require.</p>

<pre class="php">function formatDate(format, intTimeStamp)
    dim unUDate, A

    ' Test to see if intTimeStamp looks valid. If not, they have passed a normal date
    if not (isnumeric(intTimeStamp)) then
        if isdate(intTimeStamp) then
            intTimeStamp = DateDiff("S", "01/01/1970 00:00:00", intTimeStamp)
        else
            response.write "Date Invalid"
            exit function
        end if
    end if
    
    if (intTimeStamp=0) then 
        unUDate = now()
    else
        unUDate = DateAdd("s", intTimeStamp, "01/01/1970 00:00:00")
    end if

    unUDate = trim(unUDate)

    dim startM : startM = InStr(1, unUDate, "/", vbTextCompare) + 1
    dim startY : startY = InStr(startM, unUDate, "/", vbTextCompare) + 1
    dim startHour : startHour = InStr(startY, unUDate, " ", vbTextCompare) + 1
    dim startMin : startMin = InStr(startHour, unUDate, ":", vbTextCompare) + 1

    dim dateDay : dateDay = mid(unUDate, 1, 2)
    dim dateMonth : dateMonth = mid(unUDate, startM, 2)
    dim dateYear : dateYear = mid(unUDate, startY, 4)
    dim dateHour : dateHour = mid(unUDate, startHour, 2)
    dim dateMinute : dateMinute = mid(unUDate, startMin, 2)
    dim dateSecond : dateSecond = mid(unUDate, InStr(startMin, unUDate, ":", vbTextCompare) + 1, 2)

    format = replace(format, "%Y", right(dateYear, 4))
    format = replace(format, "%y", right(dateYear, 2))
    format = replace(format, "%m", dateMonth)
    format = replace(format, "%n", cint(dateMonth))
    format = replace(format, "%F", monthname(cint(dateMonth)))
    format = replace(format, "%M", left(monthname(cint(dateMonth)), 3))
    format = replace(format, "%d", dateDay)
    format = replace(format, "%j", cint(dateDay))
    format = replace(format, "%h", mid(unUDate, startHour, 2))
    format = replace(format, "%g", cint(mid(unUDate, startHour, 2)))

    if (cint(dateHour) &gt; 12) then
        A = "PM"
    else
        A = "AM"
    end if
    format = replace(format, "%A", A)
    format = replace(format, "%a", lcase(A))

    if (A = "PM") then format = replace(format, "%H", left("0" &amp; dateHour - 12, 2))
    format = replace(format, "%H", dateHour)
    if (A = "PM") then format = replace(format, "%G", left("0" &amp; cint(dateHour) - 12, 2))
    format = replace(format, "%G", cint(dateHour))

    format = replace(format, "%i", dateMinute)
    format = replace(format, "%I", cint(dateMinute))
    format = replace(format, "%s", dateSecond)
    format = replace(format, "%S", cint(dateSecond))
    format = replace(format, "%L", WeekDay(unUDate))
    format = replace(format, "%D", left(WeekDayName(WeekDay(unUDate)), 3))
    format = replace(format, "%l", WeekDayName(WeekDay(unUDate)))
    format = replace(format, "%U", intTimeStamp)
    format = replace(format, "11%O", "11th")
    format = replace(format, "1%O", "1st")
    format = replace(format, "12%O", "12th")
    format = replace(format, "2%O", "2nd")
    format = replace(format, "13%O", "13th")
    format = replace(format, "3%O", "3rd")
    format = replace(format, "%O", "th")

    formatDate = format

end function</pre> <br><br>]]></description>
				<pubDate>Mon, 15 Mar 2004 14:07:00 +0000</pubDate>
				<guid isPermaLink="false">http://www.addedbytes.com/blog/code/vbscript-date-format-functions/</guid>
				<dc:creator>Dave Child</dc:creator>
				<a href="/feeds/tag-feed/?tags=asp&amp;start=0" class="ditto_tag" rel="tag">asp</a>,<a href="/feeds/tag-feed/?tags=date&amp;start=0" class="ditto_tag" rel="tag">date</a>,<a href="/feeds/tag-feed/?tags=development&amp;start=0" class="ditto_tag" rel="tag">development</a>,<a href="/feeds/tag-feed/?tags=javascript&amp;start=0" class="ditto_tag" rel="tag">javascript</a>,<a href="/feeds/tag-feed/?tags=programming&amp;start=0" class="ditto_tag" rel="tag">programming</a>,<a href="/feeds/tag-feed/?tags=reference&amp;start=0" class="ditto_tag" rel="tag">reference</a>,<a href="/feeds/tag-feed/?tags=scripts&amp;start=0" class="ditto_tag" rel="tag">scripts</a>,<a href="/feeds/tag-feed/?tags=time&amp;start=0" class="ditto_tag" rel="tag">time</a>,<a href="/feeds/tag-feed/?tags=unix&amp;start=0" class="ditto_tag" rel="tag">unix</a>,<a href="/feeds/tag-feed/?tags=vb&amp;start=0" class="ditto_tag" rel="tag">vb</a>,<a href="/feeds/tag-feed/?tags=vbscript&amp;start=0" class="ditto_tag" rel="tag">vbscript</a>,<a href="/feeds/tag-feed/?tags=webdesign&amp;start=0" class="ditto_tag" rel="tag">webdesign</a>
			</item>

			<item>
				<title>VBScript Regular Expressions</title>
				<link>http://www.addedbytes.com/blog/code/vbscript-regular-expressions/</link>
				<description><![CDATA[ Regular expression reference and examples for VBScript. <p>Regular expressions in VBScript are two words that can bring many to their knees, weeping, but they are not as scary as some would have you believe. With their roots in Perl, regular expressions in VBScript use similar syntax, and the chances are that you may already be familiar with the concepts here if you have played with regular expression matching before.</p>

<p>Below, you will find three sections. The first section, <a href="http://www.addedbytes.com/asp/vbscript-regular-expressions/#reference">Reference</a>, is a simple reference listing the most-used of the various symbols and characters used in regular expressions. The second section, <a href="http://www.addedbytes.com/asp/vbscript-regular-expressions/#functions">Functions</a>, has two functions in it that may make life easier for you. The third section, <a href="http://www.addedbytes.com/asp/vbscript-regular-expressions/#examples">Examples</a>, is where the fun begins - examples of regular expressions in action.</p>

<h3 id="reference">Reference</h3>

<p><strong>Character Sets and Grouping</strong></p>

<ul><li class="reference"><span class="listpad">.</span> - Any single character (except new line character, "\n")</li><li class="reference"><span class="listpad">[]</span> - Encloses any set of characters</li><li class="reference"><span class="listpad">^</span> - Matches any characters not within following set</li><li class="reference"><span class="listpad">[A-Z]</span> - Any upper case letter between A and Z</li><li class="reference"><span class="listpad">[a-z]</span> - Any lower case letter between a and z</li><li class="reference"><span class="listpad">[0-9]</span> - Any digit from 0 to 9</li><li class="reference"><span class="listpad">()</span> - Group section. Also can then be back-referenced with $1 to $n, where n is the number of groups</li><li class="reference"><span class="listpad">|</span> - Or. (ab)|(bc) will match "ab" or "bc"</li></ul>

<p><strong>Repetition</strong></p>

<ul><li class="reference"><span class="listpad">+</span> - One or more</li><li class="reference"><span class="listpad">*</span> - Zero or more</li><li class="reference"><span class="listpad">?</span> - Zero or one</li><li class="reference"><span class="listpad">{5}</span> - Five</li><li class="reference"><span class="listpad">{1,3}</span> - One to three</li><li class="reference"><span class="listpad">{2,}</span> - Two or more</li></ul>

<p><strong>Positioning</strong></p>

<ul><li class="reference"><span class="listpad">^</span> - Start of string</li><li class="reference"><span class="listpad">$</span> - End of string</li><li class="reference"><span class="listpad">\b</span> - End of word</li><li class="reference"><span class="listpad">\n</span> - New line</li><li class="reference"><span class="listpad">\r</span> - Carriage return</li></ul>

<p><strong>Miscellaneous</strong></p>

<ul><li class="reference"><span class="listpad">\</span> - Escape character</li><li class="reference"><span class="listpad">\t</span> - Tab</li><li class="reference"><span class="listpad">\s</span> - White space</li><li class="reference"><span class="listpad">\w</span> - Matches word (equivalent of [A-Za-z0-9_])</li></ul>

<p>Please note that the escape character mentioned above is not usable in normal VBScript. Regular expression syntax is based upon Perl regular expression syntax. To escape a character in VBScript, you usually double it. For example, the following will print out 'This is a "quoted" piece of text'.</p>

<code>response.write("This is a ""quoted"" piece of text.")</code>

<h3 id="functions">Functions</h3>

<p>The first of the functions below, ereg (named after the PHP function to keep me from going quite quite mad), is the one you will probably use most. Simply put, if you feed in a string, pattern, and choose whether or not you would like to ignore the case of letters in either, the function will return TRUE if the string contains the pattern, or FALSE if not.</p>

<code>function ereg(strOriginalString, strPattern, varIgnoreCase)
    ' Function matches pattern, returns true or false
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    dim objRegExp : set objRegExp = new RegExp
    with objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    end with
    ereg = objRegExp.test(strOriginalString)
    set objRegExp = nothing
end function</code>

<p>Next up we have ereg_replace. Like it's shorter cousin, you need to feed it a string, a pattern and choose your case sensitivity. This time, you must also add a replacement. This function will replace all instances of the pattern with the replacement in the string (if you change ".Global = True" to ".Global = False" then the function will only replace the first instance of the pattern with the replacement).</p>

<code>function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
    ' Function replaces pattern with replacement
    ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
    dim objRegExp : set objRegExp = new RegExp
    with objRegExp
        .Pattern = strPattern
        .IgnoreCase = varIgnoreCase
        .Global = True
    end with
    ereg_replace = objRegExp.replace(strOriginalString, strReplacement)
    set objRegExp = nothing
end function</code>

<h3 id="examples">Examples</h3>

<p><strong>Example 1: Checking hexadecimal string</strong></p>

<p>A hexadecimal number can be made up of any digit, and any letter, upper or lower case, between a and f, inclusive. So to check if a string is actually hexadecimal, the following will do quite nicely (strOriginalString is the original string to be tested):</p>

<code>&lt;%
if ereg(strOriginalString, "[^a-f0-9\s]", True) = True then
    response.write "String is not hexadecimal."
else
    response.write "String is hexadecimal."
end if
%&gt;</code>

<p>The pattern, "[^a-f0-9\s]" matches anything that is <strong>not</strong> in the set of characters specified (so if there is anything in the string that is not in that set, the function will return True). The characters specified are all letters between a and f inclusive, and we've specified a case insensitive match, so upper case letters will be treated the same way. We are also allowing whitespace (new lines, spaces, carriage returns and tabs), which is what the "\s" represents in regular expressions.</p>

<p>Example string that returns False (and is therefore hexadecimal):</p>

<code>AAcc99</code>

<p><strong>Example 2: Masking the last section of an IP address</strong></p>

<p>An IP address is made up of four sets of numbers seperated by periods. It's common practice, if you are going to display visitor (or any) IP address on your site, to mask the last (fourth) set of numbers. Here's a way to use ereg_replace to do just this:</p>

<code>&lt;%
strOriginalString = ereg_replace(strOriginalString, "([^0-9])([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.[0-9]{1,3}([^0-9])", "$1$2.$3.$4.***$5", True)
%&gt;</code>

<p>This is a little more tricky, as you'd hopefully expect from a second example. It looks harder than it is though, so one step at a time. There are actually only a few entities in the pattern - they are just repeated. The most important is this: "([0-9]{1,3})". It matches a section of an IP adress, and is enclosed in brackets so that this section can be used in the replacement of the pattern as well (otherwise we would not be able to keep the first three parts of the IP address to display). You can see these sections in use, referenced with "$2", "$3" and "$4" in the replacement. The pattern within the brackets simply says "between one and three digits between 0 and 9".</p>

<p>The second repeated section is "\.". We use a backslash before the period to indicate that this period (the character following the backslash) is to be treated as a normal period. We call this an <em>escaped character</em>, and this is a fairly common practice. The period, unescaped (without the backslash), is used as a symbol representing "any character except the new line character".</p>

<p>Example input text:</p>

<code>My IP address is 123.456.78.9 but 4444.1.1.1 is just a bunch of random numbers, and so is 12.34.56, and 1.1.1.1 is another valid IP.</code>

<p>Example output text:</p>

<code>My IP address is 123.456.78.*** but 4444.1.1.1 is just a bunch of random numbers, and so is 12.34.56, and 1.1.1.*** is another valid IP.</code>

<p><strong>Example 3: Making the second word of every sentence in a string bold, as long as the word before only contains upper case letters and the second word does not contain an even digit</strong></p>

<p>Getting more interesting now, this example is not in the least bit useful in practice, but should prove to be a useful demonstration of the power of regular expressions. It sounds tough - but with regular expressions, it's a walk in the park.</p>

<code>&lt;%
strOriginalString = ereg_replace(". " &amp; strOriginalString, "(\.|!|\?)\s([A-Z]+)\s([^02468\s]+)\s", "$1 $2 &lt;strong&gt;$3&lt;/strong&gt; ", False)
strOriginalString = mid(strOriginalString, 2)
%&gt;</code>

<p>We start by adding an artificial period and space to the beginning of the string, just to make sure we catch the first sentence, and add a line to strip our extra characters out afterwards. We only want those sentences split with punctuation <em>and</em> a space, or we'll end up with bold decimals and it will be very messy indeed. So, we check for puncuation, followed by a space, followed by a word made entirely of capitals, followed by another space, followed by a second word that doesn't contain even numbers, or whitespace, followed by a space. If we find that, we replace it with the same items we picked up in brackets, only with a &lt;strong&gt;&lt;/strong&gt; tag pair around the second word.</p>

<p>Example input text:</p>

<code>THE quick brown fox jumped over the lazy dog? Many red balloons blew up! EVEN num2ber sentence. ODD num3ber sentence.</code>

<p>Example output text:</p>

<code>THE <strong>quick</strong> brown fox jumped over the lazy dog? Many red balloons blew up! EVEN num2ber sentence. ODD <strong>num3ber</strong> sentence.</code> <br><br>]]></description>
				<pubDate>Fri, 07 Nov 2003 09:29:40 +0000</pubDate>
				<guid isPermaLink="false">http://www.addedbytes.com/blog/code/vbscript-regular-expressions/</guid>
				<dc:creator>Dave Child</dc:creator>
				<a href="/feeds/tag-feed/?tags=asp&amp;start=0" class="ditto_tag" rel="tag">asp</a>,<a href="/feeds/tag-feed/?tags=code&amp;start=0" class="ditto_tag" rel="tag">code</a>,<a href="/feeds/tag-feed/?tags=expressions&amp;start=0" class="ditto_tag" rel="tag">expressions</a>,<a href="/feeds/tag-feed/?tags=programming&amp;start=0" class="ditto_tag" rel="tag">programming</a>,<a href="/feeds/tag-feed/?tags=reference&amp;start=0" class="ditto_tag" rel="tag">reference</a>,<a href="/feeds/tag-feed/?tags=regex&amp;start=0" class="ditto_tag" rel="tag">regex</a>,<a href="/feeds/tag-feed/?tags=regexp&amp;start=0" class="ditto_tag" rel="tag">regexp</a>,<a href="/feeds/tag-feed/?tags=regular&amp;start=0" class="ditto_tag" rel="tag">regular</a>,<a href="/feeds/tag-feed/?tags=regular-expressions&amp;start=0" class="ditto_tag" rel="tag">regular-expressions</a>,<a href="/feeds/tag-feed/?tags=scripting&amp;start=0" class="ditto_tag" rel="tag">scripting</a>,<a href="/feeds/tag-feed/?tags=vb&amp;start=0" class="ditto_tag" rel="tag">vb</a>,<a href="/feeds/tag-feed/?tags=vbscript&amp;start=0" class="ditto_tag" rel="tag">vbscript</a>
			</item>
	</channel>
</rss>