AdBlock Detected!

Our website is made possible by displaying ads to our visitors. Please support us by whitelisting our website.

Computer Neek

What are regular expressions

Regular expressins are series of symbols called metacharacters.

Characters to know


Reference symbol Example Meaning Matching strings
1 * xy* Zero or more elements x, xy, xyy, xyyy
2 + x+y One or more preceding elements xy, xxy, xxxy, xxxxy
3 ? call(ing)? Zero or one preceding element. call, calling
4 | (fact) | (factor) | (factoring) Separates alternatives like an OR operator fact, factor, factoring
5 () (d|D)om(ino|inic|inator) Used to group together regular expressions/ precedence Domino, Domino, dominic, Dominic, dominator, Dominator.

1) The Example in reference 1 means that the regular expression xy*, it would match any text base string that had an x and then 0 or more y's.


2) The plus(+) metacharacter means one or more preceding elements. Note that with the * it allows for 0 or more but with the plus it has to include at least one. For x + y, we must have at least one x


3) The question mark metacharacter means we can only have zero or one preceding element. It cant have it or have it but only once.


4)The pipe symbol is like the OR operator and allows for the conditions presented.


5)The parenthesis allows to determine preference.




What is a set

A set is an unordered collection of values or symbols that appears once

Read below to look at the different type of sets.



Set of all integers

To represent a set of all integers(positive and negative whole numbers), we write them out as

ℤ = {-3,-2,-1,0,1,2,3}.



Empty Sets

To represent an empty set you just use an empty curly braces { } or a the character ∅. You can also write it out as ∅ = { } but that is optional.



Infinite set

To represent an infinite set is also represented by ℕ = {0,1,2,3}.



Set of rational numbers

To represent a set of rational numbers(numbers that can be put in a fraction) its, ℚ = {1/4,1/6,3/5}.



Set of real numbers

To represent a set of real numbers(numbers that can't be put in a fraction and numbers that can be put in a fraction) its ℝ= {-18, 2.2, 7.9,ℼ }.



Things to know


Cardinality

Cardinality refers to the number of elements in a finate set. In the example below, it shows how you would use cardinality.


Example


The set is X


X = {45,62,56,90}


You would say that set X has a cardinality of 4.


A finite set

A finate set is a set that has a limited amount of items.


Infinite sets

Infinte sets, like the name suggests, are sets that have numbers that never end. ℕ,ℚ,ℤ and ℝ are all examples of infinite sets because they don't end.

Countable set

A countable set is either a set that is not infinite or a natural number set(a set with just positive numbers) that is infinite but has numbers which can be counted from one at a time

Example

N = {0, 1, 2, 3, 4 ...}


Set Comprehension

X = {x² | x ∊ ℕ ∧ n < 5}


The X{} means the set "X".


'|' means such that


'∊' means "belong to"


'ℕ' means natural numbers


'∧' means "and"


Altogther, it means,

X eauals x² such tha x belongs to the infinite set of natural numbers, including zero, and n is less than 5.

Remeber that ℕ is the symbol for natural numbers and that it is infinite since there can be an infinite amount of positive numbers.


In this example it means that we have to use the natural numbers of n that is less than 5


ℕ = {0, 1, 2, 3, 4}


and each n is going to be squared


B = {0, 1, 4, 9, 16}

This means that set be equals 0, 1, 4, 9 and 16

Cartesian product of sets

The Cartesian product of two sets is the set of all ordered pairs(a, b), where a is a member of set A and b is a member of set B


Its written as A x B but we say it as "A cross B"

Example

C = A x B


A = {2, 5, 10}


B = {4, 14, 44}


To form the cartesian product, its:

C = {(2, 4), (2, 14), (2, 44), (5, 4), (5, 44), (10, 4), (10, 14), (10, 44)}


Above, we have written each element of set A with each element of set B. To work out how many items in your cartesian product you should have, just do the number of elements in set A times the number of elements in set B.



Subsets and proper sets

In the example below. Every member in set Y is also a member in set X, so we can say Y is a subset of X

Subsets

We can write this as X ⊆ Y


If X is a subset of Y but is not equal to it, we say that X is a proper set of Y


We write that as X ⊂ Y.


Example

{6,7,3,2,6,8} ⊂ ℕ. This means that the numbers 6, 7, 3, 2, 6, 8 is a proper set of natural numbers. They are not equal to ℕ since ℕ is infinite


Union

By using union, we are able to append all the contents of one set to another


Example


X = {4, 2,6}


Y = {7, 9, 10}


X ∪ Y = {2, 4, 6, 7, 9, 10}

union image

Intersection

Intersection set contains all the comman elements that two sets have


Example


X = {1, 7, 5, 4, 9, 0}


X = {12, 7, 9, 4, 13, 55}


X &cap Y = {4, 7, 9};



Compliment


The difference set consisits elements in one set that are not members of the other set


X = {1, 2, 4, 8, 9}


Y = {1, 8, 5, 10, 12}


X \ Y = {4, 5, 10, 12}


This reads as everything which is in set X but not in set Y.

To read about Backus-Naur Form click here or to read about different topics, click here