Wednesday, January 14, 2009

Wildcard , Plus and Star

So what you've learnt so far is some very basic matching. We will now learn using the wildcard dot, plus and star

The dot is used to replace a single character. Let’s return so our sample string. Let’s match from t to l. Start The Regex Coach and enter t , put five dots and l. Now copy our sample string into the field below.


This text is all about the complicated stuff.

Now edit your regexp and put more dots between the letters and watch what happens.

The dot is a wildcard for any other letter or whitespace. But it has to match exactly once.

If we don’t know how many characters are between our boundaries it is possible to use repetition with the +. Leave your sample text unchanged and type in the regular expression


This text is all about the complicated stuff.

Putting the + after the wildcard dot means that the dot may occur several times.

By using the star instead of the plus you will have almost the same effect. The difference is that putting a star behind means that it does not need to match at all.

Try the difference between + and * .

e.*x and e.+x

You may also use them without the wildcard. Try l+ f+


No comments:

Post a Comment