diff --git a/README.md b/README.md index d520684..be3bf08 100644 --- a/README.md +++ b/README.md @@ -54,18 +54,18 @@ The meta character are as follows: |Meta character|Description| |:----:|----| -|.|Period matches any single character except a line break.| -|[ ]|Character class. Matches any character contained between the square brackets.| -|[^ ]|Negated character class. Matches any character that is not contained between the square brackets| -|*|Matches 0 or more repetitions of the preceding symbol.| -|+|Matches 1 or more repetitions of the preceding symbol. -|?|Makes the preceding symbol optional.| -|{n}|Braces. Matches ā€œnā€ repetitions of the preceding symbol.| -|(xyz)|Character group. Matches the characters xyz in that exact order.| -|||Alternation. Matches either the characters before or the characters after the symbol.| -|\|Escapes the next character. This allows you to match reserved characters [ ] ( ) { } . * + ? ^ $ \ || -|^|Matches the beginning of the input.| -|$|Matches the end of the input.| +|.|Period matches any single character except a line break.| +|[ ]|Character class. Matches any character contained between the square brackets.| +|[^ ]|Negated character class. Matches any character that is not contained between the square brackets| +|*|Matches 0 or more repetitions of the preceding symbol.| +|+|Matches 1 or more repetitions of the preceding symbol. +|?|Makes the preceding symbol optional.| +|{n}|Braces. Matches ā€œnā€ repetitions of the preceding symbol.| +|(xyz)|Character group. Matches the characters xyz in that exact order.| +|||Alternation. Matches either the characters before or the characters after the symbol.| +|\|Escapes the next character. This allows you to match reserved characters [ ] ( ) { } . * + ? ^ $ \ || +|^|Matches the beginning of the input.| +|$|Matches the end of the input.| ## 2.1 Full stop @@ -87,6 +87,12 @@ expression `[Tt]he` means: an uppercase `T` or lowercase `t`, followed by the le "[Tt]he" => The car parked in the garage. +Just like above example the regular expression `ar[.]` means: an lowercase character `a`, followed by letter `r`, followed by any character. + +
+"ar[.]" => The car parked in the garage.
+
+ ### 2.2.1 Negated character set In general the caret symbol represents the start of the string, but when it is typed after the opening square bracket it negates the @@ -98,11 +104,49 @@ the letter `r`. -### 2.2.2 Repeating character set +## 2.3 Repetitions -We can repeat a character class by using `+`, `*` or `?` operators. For example the regular expression `[a-z]+` means: any number of -lowercase letters in a row. +Following meta characters `+`, `*` or `?` are used to specify how many times a subpattern can occurs. These meta characters act +differently in different situations. + +### 2.3.1 The Star + +The symbol `*` matches zero or more repetitions of the preceding matcher. The regular expression `a*` means: zero or more repetitions +of preceding lowercase character `a`. But if it apperas after a character set or class that it finds the repetitions of the whole +character set. For example the regular expression `[a-z]*` means: any number of lowercase letters in a row.
-"[a-z]+" => The car parked in the garage.
+"[a-z]*" => The car parked in the garage #21.
 
+ +The `*` symbol can be used with the meta character `.` to match any string of characters `.*`. The `*` symbol can be used with the +whitespace character `\s` to match a string of whitespace characters. For example the expression `\s*cat\s*` means: zero or more +spaces, followed by lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `t`, followed by +zero or more spaces. + +
+"\s*cat\s*" => The fat cat sat on the cat.
+
+ +### 2.3.2 The Plus + +The symbol `+` matches one or more repetitions of the preceding character. For example the regular expression `c.+t` means: lowercase +letter `c`, followed by any number of character, followed by the lowercase character `t`. + +
+"c.+t" => The fat cat sat on the mat.
+
+ +### 2.3.3 The Question Mark + +In regular expression the meta character `?` makes the preceding character optional. This symbol matches zero or more repetitions of +the preceding character. For example the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase +character `h`, followed by the lowercase character `e`. + +
+"[T]he" => The car is parked in the garage.
+
+
+"[T]?he" => The car is parked in the garage.
+
+