Thursday, January 3, 2008

.* Pattern in Regular Expression

A dot (.) in regular expression means any character whatsoever except the newline character.
A start (*) means 0 or more occurrence of the previous character.
Therefore the dot-star (.*) combination in a regular expression means "some sequence of characters on the same line" or "simply nothing".

Example content:

<body>
anything goes here...
</body>

Regular expression:
<body>.*</body>

Search result:
Will not match anything

But if the example content is:

<body>anything goes here...</body>

and the Regular is expression as before:
<body>.*</body>

Search result:
Will match the whole string including the <body>...</body> tags.

No comments: