From 8fafd4f9de1a6ac08d85ceb733ed9c10f53f625b Mon Sep 17 00:00:00 2001
From: Aakash Panchal <51417248+Aakash-Panchal27@users.noreply.github.com>
Date: Sun, 16 Feb 2020 19:35:11 +0530
Subject: [PATCH] Update Regex_pending.md
---
Akash Articles/Regex_pending.md | 90 +++++++++++++++++++++------------
1 file changed, 57 insertions(+), 33 deletions(-)
diff --git a/Akash Articles/Regex_pending.md b/Akash Articles/Regex_pending.md
index dad8047..4e88161 100644
--- a/Akash Articles/Regex_pending.md
+++ b/Akash Articles/Regex_pending.md
@@ -1,3 +1,4 @@
+
## Regular Expression (RegEx)
While filling online forms, haven't you come across errors like "Please enter valid email address" or "Please enter valid phone number".
@@ -5,13 +6,12 @@ While filling online forms, haven't you come across errors like "Please enter va
Annoying as they may be, there's a lot of black magic that the computer does before it determines that, the details you've entered are incorrect.
Can you think out, what is that black magic? If you are familar with algorithms, then you will say, we can write an algorithm for the same.
-Yes, we can write an algorithm to verify different things.
-But we have a standard tool which is particularly designed for the similar kind of purposes.
+Yes, we can write an algorithm to verify different things. But we have a standard tool which is particularly designed for the similar kind of purposes.
It is **Regular Expression**. We call it **RegEx** for short. RegEx makes our work a lot easier. Let's see some basic examples where RegEx becomes handy.
-Suppose, you are in search of an averge price of a particular product on amazon. The following regular expression will find you any price($12, $75.50) on the webpage: `\$([0-9]+)\.([0-9]+)`.
+Suppose, you are in search of an averge price of a particular product on amazon. The following regular expression will find you any price(\$12, \$75.50) on the webpage: `\$([0-9]+)\.([0-9]+)`.
Quite interesting!
@@ -42,7 +42,7 @@ Simple matching of a specific word can be done as the following:

-As you can see it matches "Reg" in the text. Similarly, what will be the match for pattern **"Ex"** in the same text above?
+As you can see it matches "Reg" in the text. Similarly, what will be the match for "Ex" in the same text above?

@@ -97,9 +97,9 @@ What if you want to match both "soon" and "moon" or basically words ending with

-What did you observe? You can see that adding $[sm]$ matches both $soon$ and $moon$. Here $[sm]$ is called character class, which is basically a list of characters we want to match.
+What did you observe? You can see that adding `[sm]` matches both $soon$ and $moon$. Here `[sm]` is called character class, which is basically a list of characters we want to match.
-More formally, $[abc]$ is basically either $a$ or $b$ or $c$.
+More formally, `[abc]` is basically either `a` or `b` or `c`.
Predict the output of the following:
@@ -118,7 +118,7 @@ Answer:

-Now, if we put **^**, then it will show a match for characters other than the ones in the bracket.
+Now, if we put `^`, then it will show a match for characters other than the ones in the bracket.

@@ -132,7 +132,7 @@ Answer:

-Writing every characters(like $[0123456789]$ or [abcd]) is some what slow and also errorneous, what is the short-cut?
+Writing every characters(like `[0123456789]` or `[abcd]`) is some what slow and also errorneous, what is the short-cut?
## Ranges
Ranges makes our work easier. Consecutive characters can simply be replaced by putting a dash between the first and last character.
@@ -160,25 +160,25 @@ Answer:
## Predefined Character Classes
- 1. **\w & \W**: '**\w**' is just a short form of a character class [A-Za-Z0-9_].
+ 1. **`\w` & `\W`**: `\w` is just a short form of a character class `[A-Za-Z0-9_]`.

- \W is equivalent to ``[^\w]``.
+ `\W` is equivalent to ``[^\w]``.

- 2. **\d & \D**: '**\d**' matches any digit character. It is equivalent to character class [0-9].
+ 2. **`\d` & `\D`**: `\d` matches any digit character. It is equivalent to character class `[0-9]`.

- \D is equivalent to ``[^\d]``.
+ `\D` is equivalent to ``[^\d]``.

-3. **\s & \S**: '**\s**' matches white space characters. Tab('**\t**'), newline('**\n**') & space(' ') are whitespace characters.
+3. **`\s` & `\S`**: `\s` matches white space characters. Tab(`\t`), newline(`\n`) & space(` `) are whitespace characters.

- Similarly, \S is equivalent to ``[^\s]``.
+ Similarly, `\S` is equivalent to ``[^\s]``.

- 4. **dot(.)**: Dot matches any character except **\n**(line break or new line character) and **\r**(carriage-return character). It is known as **wildcard matching**.
+ 4. **dot(`.`)**: Dot matches any character except `\n`(line break or new line character) and `\r`(carriage-return character). It is known as **wildcard matching**.

@@ -190,8 +190,9 @@ Predict the output of the following regex:
**Text:** Binary to decimal data: 001- 1, 010- 2, 011- 3, a01- 4, 100- 4.
Answer:

-2. **RegEx code:** ``[01][01][0-1]\W\s\d``
- **Text:** Binary to decimal data:
+2. **RegEx code:**
+**Text:**
+
## Alternation (OR operator)
@@ -219,12 +220,16 @@ Can you observe anything from it?
**OR operator** tries to match starting from the first word(in the expression), if it is a match, then it will not try to match next word(in the expression) at the same place in text.
Predict the output of the following regex:
-1.
-2.
+1. **RegEx code:**
+**Text:**
+
+2. **RegEx code:**
+**Text:**
+
## Quantifiers (Repetition)
-We have seen that to match 3 digit patterns we can use ``[0-9][0-9][0-9]``. What if we have n digit patterns? We have to write [0-9] n times, but that is really waste of time. Here is when quantifiers comes for help.
+We have seen that to match 3 digit patterns we can use ``[0-9][0-9][0-9]``. What if we have n digit patterns? We have to write `[0-9]` n times, but that is really waste of time. Here is when quantifiers comes for help.
1. **Limiting repetitions(``{min, max}``):** To match n digit pattern we can simply write ``[0-9]{n}``. Instead of ``{n}`` by providing minimum and maximum values as ``[0-9]{min, max}``, we can match a pattern repeating min to max times.
@@ -246,7 +251,9 @@ Let's

**Nature of Quantifiers:**
-HTML tag is represented as