..
In a previous article of my friend and colleague Luca Ruggiero we saw how to start working with the ISAPI filter for rewriting the URLs on IIS.
This article stands as a sort of continuation of the path already started and aims to explain a little 'theory in order to allow you to write instructions for rewriting increasingly complex and articulated with the support of regular expressions.
Special characters
We begin by seeing the cd. special characters, ie those characters that have special meaning in relation to their classical value text:
| Character | Meaning |
| . | Any character |
| * | Zero or more repetitions of the character to the left |
| + | One or more repetitions of the character to the left |
| ? | The character to the left may be present or not |
| | | Choice between what is right and the left |
| ^ | Top of the line or symbol of denial if used within a set of characters |
| $ | End of line |
| (E) | They are used to create the sub-expressions, or to identify the variable that will then be called with $ N |
| {And} | They are used to indicate the minimum and maximum length of the string to the left |
| [And] | It contains a set of characters |
.Means any character and therefore accepts a (uno!) any character.
.*The expression above is always verified, because it accepts an empty string is any string, as our symbology includes a repeat indefinitely (from zero to infinity) of any characters.
ab *This expression is tested with the following results: "a", "ab", "abb", "abbb", "abbbb ",...
ab +Occurs with "ab", "abb", "abbb ",... but not with "a"!
ab?Occurs with "a" or "ab".
{ab} 2.4
Occurs with "abb", "abbb", "abbbb".
^ A. *Occurs with any string that begins with the letter "a"
.* Z $Occurs with any string that ends with the letter "z"
^ C * a $Occurs with any string that begins with "c" and ends with the letter "a". For example: "home", "Paper", "glue", etc..
abc | defOccurs with "abc" or with "def"
a (b | c)Occurs with "ab" or with "ac". To achieve this we used a pair of parentheses to create a sub-expression in contemplation, in our example, the choice between "b" and "c"
[Az]With the use of square brackets we have created a set of characters. In our example we have provided a range of characters ranging from "a" through "z" and then embraces the whole alphabet.
[A-zA-Z]The expression above, however, shows us how to accept all these alphabet characters are case-insensitive.
[0-9]This expression includes any number between 0 and 9.
[^ 0-9]This expression includes any character except numbers. We did this by using denial, at the beginning of our set, the special character ^.
Obviously, arranging and combining the various example above you will notice that it is possible to predict a nearly infinite number of possibilities.
Finally, of course, we must consider the possibility that the characters seen above we can serve in their classical value, ie as mere characters.
In this case we make use of the escape character (\) before the special character that we want to use as a common character.
For example we see how to write, in the form of esepressione, the string "page.html".
As we know the point is a special character and, therefore, easy to use as a point we have to do this:
page \. htmlNote, of course, that the same escape character is, in turn, a special character and therefore, if you want to use it in its literal common value, we must have recourse to a double-escape:
\ \
| |
ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €. |
| |
ASP Zero (Ebook)
Learning Microsoft ASP and VBScript from scratch. At only 29 €. |
| |
ASP.NET (Course)
Full course for building Web applications from 49 €. |