You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 12_Day/12_day_regular_expressions.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,22 +19,22 @@
19
19
20
20
-[📘 Day 12](#%f0%9f%93%98-day-12)
21
21
-[Regular Expressions](#regular-expressions)
22
-
-[RegEx parameters](#regex-parameters)
22
+
-[RegExp parameters](#regex-parameters)
23
23
-[Pattern](#pattern)
24
24
-[Flags](#flags)
25
-
-[Creating a pattern with RegEx Constructor](#creating-a-pattern-with-regex-constructor)
26
-
-[Creating a pattern without RegEx Constructor](#creating-a-pattern-without-regex-constructor)
27
-
-[RegExp Object Methods](#regexp-object-methods)
25
+
-[Creating a pattern with RegExp Constructor](#creating-a-pattern-with-regex-constructor)
26
+
-[Creating a pattern without RegExp Constructor](#creating-a-pattern-without-regex-constructor)
27
+
-[RegExpp Object Methods](#regexp-object-methods)
28
28
-[Testing for a match](#testing-for-a-match)
29
29
-[Array containing all of the match](#array-containing-all-of-the-match)
30
30
-[Replacing a substring](#replacing-a-substring)
31
31
-[Square Bracket](#square-bracket)
32
-
-[Escape character(\\) in RegEx](#escape-character-in-regex)
32
+
-[Escape character(\\) in RegExp](#escape-character-in-regex)
33
33
-[One or more times(+)](#one-or-more-times)
34
34
-[Period(.)](#period)
35
35
-[Zero or more times(*)](#zero-or-more-times)
36
36
-[Zero or one times(?)](#zero-or-one-times)
37
-
-[Quantifier in RegEx](#quantifier-in-regex)
37
+
-[Quantifier in RegExp](#quantifier-in-regex)
38
38
-[Cart ^](#cart)
39
39
-[Exact match](#exact-match)
40
40
-[💻 Exercises](#%f0%9f%92%bb-exercises)
@@ -46,11 +46,11 @@
46
46
47
47
## Regular Expressions
48
48
49
-
A regular expression or RegEx is a small programming language that helps to find pattern in data. A RegEx can be used to check if some pattern exists in a different data types. To use RegEx in JavaScript either we use RegEx constructor or we can declare a RegEx pattern using two forward slashes followed by a flag. We can create a pattern in two ways.
49
+
A regular expression or RegExp is a small programming language that helps to find pattern in data. A RegExp can be used to check if some pattern exists in a different data types. To use RegExp in JavaScript either we use RegExp constructor or we can declare a RegExp pattern using two forward slashes followed by a flag. We can create a pattern in two ways.
50
50
51
51
To declare a string we use a single quote, double quote a backtick to declare a regular expression we use two forward slashes and an optional flag. The flag could be g, i, m, s, u or y.
52
52
53
-
### RegEx parameters
53
+
### RegExp parameters
54
54
55
55
A regular expression takes two parameters. One required search pattern and an optional flag.
56
56
@@ -66,47 +66,47 @@ Flags are optional parameters in a regular expression which determine the type o
66
66
- i: case insensitive flag(it searches for both lowercase and uppercase)
67
67
- m: multiline
68
68
69
-
### Creating a pattern with RegEx Constructor
69
+
### Creating a pattern with RegExp Constructor
70
70
71
71
Declaring regular expression without global flag and case insensitive flag.
72
72
73
73
```js
74
74
// without flag
75
75
let pattern ='love'
76
-
let regEx =newRegEx(pattern)
76
+
let regEx =newRegExp(pattern)
77
77
```
78
78
79
79
Declaring regular expression with global flag and case insensitive flag.
80
80
81
81
```js
82
82
let pattern ='love'
83
83
let flag ='gi'
84
-
let regEx =newRegEx(pattern, flag)
84
+
let regEx =newRegExp(pattern, flag)
85
85
```
86
86
87
-
Declaring a regex pattern using RegEx object. Writing the pattern and the flag inside the RegEx constructor
87
+
Declaring a regex pattern using RegExp object. Writing the pattern and the flag inside the RegExp constructor
88
88
89
89
```js
90
-
let regEx =newRegEx('love','gi')
90
+
let regEx =newRegExp('love','gi')
91
91
```
92
92
93
-
### Creating a pattern without RegEx Constructor
93
+
### Creating a pattern without RegExp Constructor
94
94
95
95
Declaring regular expression with global flag and case insensitive flag.
96
96
97
97
```js
98
98
let regEx=/love/gi
99
99
```
100
100
101
-
The above regular expression is the same as the one which we created with RegEx constructor
101
+
The above regular expression is the same as the one which we created with RegExp constructor
102
102
103
103
```js
104
-
let regEx=newRegEx('love','gi')
104
+
let regEx=newRegExp('love','gi')
105
105
```
106
106
107
-
### RegExp Object Methods
107
+
### RegExpp Object Methods
108
108
109
-
Let see some of RegEx methods
109
+
Let see some of RegExp methods
110
110
111
111
#### Testing for a match
112
112
@@ -297,7 +297,7 @@ console.log(matches)
297
297
298
298
Using the square bracket and or operator , we manage to extract Apple, apple, Banana and banana.
299
299
300
-
### Escape character(\\) in RegEx
300
+
### Escape character(\\) in RegExp
301
301
302
302
```js
303
303
constpattern=/\d/g// d is a special character which means digits
We can specify the length of the substring we look for in a text, using a curly bracket. Lets imagine, we are interested in substring that their length are 4 characters
0 commit comments