Monday, December 3, 2012

Regular Expressions



A regular expression is a powerful search pattern that is used in programming. It helps identifying sequence of words, characters, or patterns of characters. Regular expression is used in many computer languages like python, java , c, c++.

CSC236 is focusing more on binary digits, strings of 0s and 1s and the different ways to express them by using different regular expressions.

Some of the important characters that are highly used in our course are:
*(star) : Repeats the previous item zero or more times.
+         : Repeats the previous item one or more times.

Here is an example:
Lets say we want to write a regular expression that accepts a string that contains multiple of 3  0s
To write the description of the language we can write:
L = s in {0,1}*| s contains multiple of 3 0s

It is easier for me to reach the regular expression wanted is to give myself examples of what should accept the description of the language and what shouldn’t

examples
empty string,  1, 11, 000, 0100, 101010, 0100000, 000100100010 accepts
0,00, 10, 1001, 10000, 0101010, 0000110 does not accept

So by looking at these examples I can say that all the 1s could be anywhere in the location and would not affect the final result of the language’s description
Only the 0s matter

Then      3 * 0 = 0
                3 * 1 = 3
                3 * 2 = 6
                3 * 3 = 9
                3 * 4 = 12

Thus we should have (0 or 3 or 6 or 9 or 12 or …. And so on) 0s. all are multiples of 3

If we have a string that contains only 0s then our regular expression should look like this:
(000)*  by following the definition of the *(star) from above

But it is not,  we need to include the 1s in which they should not affect the 0s

Then I believe our regular expression should look like this
(1*01*01*01*)*

        Since I already started learning regular expression in my other courses, I find that CSC236 helped me strengthening my understanding of the language, as well as it cleared many questions that were running in my head. 

No comments:

Post a Comment