A Regular Expression is simply a pattern that can be matched against something. Generally their use falls into two categories :
ValidationAlmost everyday we fill a form in whether electronically or on paper which contains fields which have a required format, for example Phone Numbers, Social Security Numbers, Order Numbers etc, all of these are in a set format. We can test the input to ensure that it confirms to the known format, for example phone numbers in the UK are in two parts, a five digit area code and a seven digit phone number, so we have a pattern against which we can test anything that 'should' be a UK phone number as shown below :All we can test with this is that the data entered matched a provided format for that field, not that the value is actually a true value, I could have entered an entire string of 0's which is not an actual code, but it still passes our validation as it matches the pattern. Search & ReplaceMany of you will have used Search & Replace tools, there is one in Microsoft Word for example, their sole purpose is to replace one set of characters with another, for example replace every occurance of 2002 with 2003 as in the following example :
|